Bot API Backward Compatibility - python-telegram-bot/dev-wiki GitHub Wiki
This page is an addition to the stability policy and is intended to be a helpful reference for the developers when working on Bot API updates that introudce backward incompatible changes.
A few cases can happen when Telegram makes changes to arguments of classes and methods. Here are a few hints on how these can be handled in a compatible way that is backward compatible or at least minimizes the impact of the change. Whether these hints are applied or the change is just implemented in a breaking way may be decided by the dev team on a case-by-case basis. This depends e.g. on the currently available capacity.
-
Optional arguments become mandatory
- Keep the argument optional in the method signature
- If the argument is not passed, raise a
TypeError
with a helpful message
That way it's still a breaking change, but at least passed values are not randomly assigned to the wrong argument.
-
New positional argument is added and changes the order of the arguments
- Add it as optional argument
- If the argument is not passed, raise a
TypeError
with a helpful message
-
Optional argument is renamed
- Keep the old argument name in the method signature
- If the old argument is passed, issue a deprecation warning with a helpful message
- If both the old and the new argument are passed, raise a
ValueError
with a helpful message.
-
Mandatory argument is renamed
- Keep the old argument name in the method signature and make it optional
- If the old argument is passed, issue a deprecation warning with a helpful message
- If neither the old nor the new argument is passed, raise a
TypeError
with a helpful message - If the old argument is not the first mandatory argument, make the ones before optional as well and raise a
TypeError
if they are not passed