@@ -15,7 +15,7 @@ Abstract
15
15
16
16
This PEP proposes a mechanism for type checking metadata that uses
17
17
the :py:data: `typing.Annotated ` type. Metadata objects that implement
18
- the new ``__supports_type__ `` protocol will be type checked by static
18
+ the new ``__supports_annotated_base__ `` protocol will be type checked by static
19
19
type checkers to ensure that the metadata is valid for the given type.
20
20
21
21
Motivation
@@ -47,11 +47,11 @@ Specification
47
47
=============
48
48
This PEP introduces a protocol that can be used by static and runtime type checkers to validate
49
49
the consistency between ``Annotated `` metadata and a given type.
50
- Objects that implement this protocol have an attribute called ``__supports_type__ ``
50
+ Objects that implement this protocol have an attribute called ``__supports_annotated_base__ ``
51
51
that specifies whether the metadata is valid for a given type::
52
52
53
53
class Int64:
54
- __supports_type__ : int
54
+ __supports_annotated_base__ : int
55
55
56
56
The attribute may also be marked as a ``ClassVar `` to avoid interaction with dataclasses::
57
57
@@ -61,14 +61,14 @@ The attribute may also be marked as a ``ClassVar`` to avoid interaction with dat
61
61
@dataclass
62
62
class Gt:
63
63
value: int
64
- __supports_type__ : ClassVar[int]
64
+ __supports_annotated_base__ : ClassVar[int]
65
65
66
66
When a static type checker encounters a type expression of the form ``Annotated[T, M1, M2, ...] ``,
67
67
it should enforce that for each metadata element in ``M1, M2, ... ``, one of the following is true:
68
68
69
- * The metadata element evaluates to an object that does not have a ``__supports_type__ `` attribute; or
70
- * The metadata element evaluates to an object ``M `` that has a ``__supports_type__ `` attribute;
71
- and ``T `` is assignable to the type of ``M.__supports_type__ ``.
69
+ * The metadata element evaluates to an object that does not have a ``__supports_annotated_base__ `` attribute; or
70
+ * The metadata element evaluates to an object ``M `` that has a ``__supports_annotated_base__ `` attribute;
71
+ and ``T `` is assignable to the type of ``M.__supports_annotated_base__ ``.
72
72
73
73
To support generic ``Gt `` metadata, one might write::
74
74
@@ -79,7 +79,7 @@ To support generic ``Gt`` metadata, one might write::
79
79
...
80
80
81
81
class Gt[T]:
82
- __supports_type__ : ClassVar[SupportsGt[T]]
82
+ __supports_annotated_base__ : ClassVar[SupportsGt[T]]
83
83
84
84
def __init__(self, value: T) -> None:
85
85
self.value = value
@@ -137,8 +137,8 @@ does not generally use marker base classes. In addition, it provides less flexib
137
137
the current proposal: it would not allow overloads, and it would require metadata objects
138
138
to add a new base class, which may make their runtime implementation more complex.
139
139
140
- Using a method instead of an attribute for ``__supports_type__ ``
141
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140
+ Using a method instead of an attribute for ``__supports_annotated_base__ ``
141
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142
142
143
143
We considered using a method instead of an attribute for the protocol, so that this method can be used
144
144
at runtime to check the validity of the metadata and to support overloads or returning boolean literals.
0 commit comments