PEP 746: small clarification to specification. (#3828)

This commit is contained in:
Rebecca Chen 2024-06-12 02:19:05 -04:00 committed by GitHub
parent e8273d3ed3
commit 1a199b5080
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 5 deletions

View File

@ -63,11 +63,10 @@ The protocol being introduced would be defined as follows if it were to be defin
When a static type checker encounters a type expression of the form ``Annotated[T, M1, M2, ...]``,
it should enforce that for each metadata element in ``M1, M2, ...``, one of the following is true:
* The metadata element evaluates to a type that does not have a ``__supports_type__`` method; or
* The metadata element evaluates to an object ``M`` that has a ``__supports_type__`` method, and
a call to ``M.__supports_type__(T)`` type checks without errors (i.e., ``T`` is assignable to the
parameter type of the ``__supports_type__`` method), and that call does not
evaluate to ``Literal[False]``.
* The metadata element evaluates to an object that does not have a ``__supports_type__`` attribute; or
* The metadata element evaluates to an object ``M`` that implements the ``SupportsType`` protocol;
and, with ``T`` instantiated to a value ``v``, a call to ``M.__supports_type__(v)`` type checks without errors;
and that call does not evaluate to ``Literal[False]``.
The body of the ``__supports_type__`` method is not used to check the validity of the metadata
and static type checkers can ignore it. However, tools that use the annotation at