aiogram.utils.deprecated.deprecated(reason, stacklevel=2)Callable[source]

This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.


aiogram.utils.deprecated.renamed_argument(old_name: str, new_name: str, until_version: str, stacklevel: int = 3)[source]

A meta-decorator to mark an argument as deprecated.

@renamed_argument("chat", "chat_id", "3.0")  # stacklevel=3 by default
@renamed_argument("user", "user_id", "3.0", stacklevel=4)
def some_function(user_id, chat_id=None):
    print(f"user_id={user_id}, chat_id={chat_id}")

some_function(user=123)  #  prints 'user_id=123, chat_id=None' with warning
some_function(123)  #  prints 'user_id=123, chat_id=None' without warning
some_function(user_id=123)  #  prints 'user_id=123, chat_id=None' without warning
  • old_name

  • new_name

  • until_version – the version in which the argument is scheduled to be removed

  • stacklevel – leave it to default if it’s the first decorator used.

Increment with any new decorator used. :return: decorator

class aiogram.utils.deprecated.DeprecatedReadOnlyClassVar(warning_message: str, new_value_getter: Callable[[aiogram.utils.deprecated._OwnerCls], aiogram.utils.deprecated._VT])[source]

DeprecatedReadOnlyClassVar[Owner, ValueType]

  • warning_message – Warning message when getter gets called

  • new_value_getter – Any callable with (owner_class: Type[Owner]) -> ValueType signature that will be executed

Usage example:

>>> class MyClass:
...     some_attribute: DeprecatedReadOnlyClassVar[MyClass, int] =     ...            DeprecatedReadOnlyClassVar(
...                  "Warning message.", lambda owner: 15)
>>> MyClass.some_attribute  # does warning.warn with `Warning message` and returns 15 in the current case