altdesktop / python-dbus-next

🚌 The next great DBus library for Python with asyncio support
https://python-dbus-next.readthedocs.io/en/latest/
MIT License
187 stars 58 forks source link

PEP 593: Allow Annotated as type annotation #150

Open ldet opened 1 year ago

ldet commented 1 year ago

To better support static type checkers PEP 593 introduced a new method for custom type annotations in Python 3.9 via typing.Annotated. The addition has been backported to older Python versions via typing-extensions.

The feature is entirely optional and does not require any additional dependencies when not being used and simple string annotations are still allowed.

All the decorators are still marked @no_type_check_decorator, but not all type checkers respect that (e.g. pyright).

Example:

@method()
def some_method(self, one: Annotated[str, 's'], two: Annotated[str, 's']) -> Annotated[str, 's']:
    return 'hello'