Skip to content

Commit

Permalink
PEP 746: small clarification to specification. (#3828)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchen152 authored Jun 12, 2024
1 parent e8273d3 commit 1a199b5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions peps/pep-0746.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a199b5

Please sign in to comment.