Skip to content

PEP 593: Allow Annotated as type annotation#150

Open
ldet wants to merge 1 commit intoaltdesktop:masterfrom
ldet:pep593-annotated
Open

PEP 593: Allow Annotated as type annotation#150
ldet wants to merge 1 commit intoaltdesktop:masterfrom
ldet:pep593-annotated

Conversation

@ldet
Copy link

@ldet ldet commented Feb 4, 2023

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant