Types alignment + new classes - #2625
Conversation
…aligned spacing. More classes filled with type hints. Additional: Update annotated. ReplyKeyboardMarkup, InlineKeyboardMarkup added force_reply DisabledButton - added Some missing fields added to init
… are checked for 'is None' in to_dict.
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@coder2020official I know what you'll think about me when you'll see this update... But without unification it's hard to teach AI to do something valuable and reproducable. I did my best to align all types.py to a single principles, signatures etc. PS. Damn... It even cannot be reviewed... 🙈🙈🙈 |
There was a problem hiding this comment.
🟡 Changes recommended
The diff disables existing tests (unconditional returns / commented assertions), which hides regressions instead of updating expectations to match the new type alignment.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
tests/test_types.py:2368
- This test is currently bypassed with an unconditional
return, and its expectations no longer match the implementation:StarTransaction.idis documented/typed asstr, andreceiveris deserialized into aTransactionPartnersubclass (not a raw dict). Updating the JSON and assertions keeps the test meaningful under the new type alignment.
json_str = r'{"id": 1, "amount": 100, "date": 1682189507, "source": {"type": "fragment"}, "receiver": {"type": "telegram_ads"}, "nanostar_amount": 10000000}'
result = types.StarTransaction.de_json(json_str)
return #Todo fix tests
assert isinstance(result, types.StarTransaction)
- Files reviewed: 1/2 changed files
- Comments generated: 2
- Review effort level: Lite
|
As a bonus for this alignment where are fixes of several found bugs (not too significant, but bugs)... uni v2.txt I reviewed this diff several times diff by diff... |
Tests fixed and upped to date
Speaking of bugs, there is a bug in async_telebot.py where the logging calls have their conditions evaluated backwards. except Exception as e:
if logger_level and logger_level >= logging.ERROR:
logger.error("Infinity polling exception: %s", self.__hide_token(str(e)))
if logger_level and logger_level >= logging.DEBUG:
logger.error("Exception traceback:\n%s", self.__hide_token(traceback.format_exc()))You can find it here. This is the opposite of what you want. logging.debug = 10 A user sets logging to info level: The > should be flipped to < in all cases. I think there's four. Just search for logger and you'll find it. |
Description
13 new classes from Bot API 10.3 update.
Lot of types alignment.
Summary
This series of 9 commits restructures
telebot/types.py(~18k changes) to align all classes with the documented coding conventions: unifiedDictionaryable/to_dict()/to_json()pattern, consistentde_json()with explicitcls(**obj)return, full type hints, complete docstrings (:param/:type/:return), proper__init__spacing, andis Noneguards on optional fields into_dict().Commits
:param/:type/:returnblocks.:param/:typeentries to docstrings.__init__signatures.__init__parameter layout: aligned to limited line width with consistent grouping.Dictionaryable.to_dict()pattern: start withdata = super().to_dict()(or{}for abstract bases), add each field, returndata.is Noneguards for all optional fields into_dict().to_dict()+json.dumps. Addedto_json()→json.dumps(self.to_dict())everywhere missing.json_dict,result, etc.) with uniformdata.de_json()methods where conditional checks were missing or incorrect.Optionalfields in__init__are properly handled inde_json().Key patterns applied
Dictionaryableand/orJsonSerializable/JsonDeserializable.to_dict():data = super().to_dict()→ populate fields →return data. Optional fields guarded withif self.field is not None.to_json(): Alwaysreturn json.dumps(self.to_dict()).de_json():obj = cls.check_json(json_string)→ deserialize nested objects with.de_json()→return cls(**obj).__init__: Type hints on all params, grouped logically, aligned line width,**kwargspassed through.:param name: description+:type name: :obj:\Type`+:return: Instance of the class+:rtype:`.