|
42 | 42 | 'TypedDict', |
43 | 43 |
|
44 | 44 | # Structural checks, a.k.a. protocols. |
| 45 | + 'MappingAuxiliary', |
45 | 46 | 'SupportsIndex', |
46 | 47 |
|
47 | 48 | # One-off things. |
@@ -145,7 +146,9 @@ def _collect_type_vars(types, typevar_types=None): |
145 | 146 | # (These are not for export.) |
146 | 147 | T = typing.TypeVar('T') # Any type. |
147 | 148 | KT = typing.TypeVar('KT') # Key type. |
| 149 | +KT_co = typing.TypeVar('KT', covariant=True) # Covariant key type. |
148 | 150 | VT = typing.TypeVar('VT') # Value type. |
| 151 | +VT_co = typing.TypeVar('VT', covariant=True) # Value type. |
149 | 152 | T_co = typing.TypeVar('T_co', covariant=True) # Any type covariant containers. |
150 | 153 | T_contra = typing.TypeVar('T_contra', contravariant=True) # Ditto contravariant. |
151 | 154 |
|
@@ -603,6 +606,19 @@ def runtime_checkable(cls): |
603 | 606 | runtime = runtime_checkable |
604 | 607 |
|
605 | 608 |
|
| 609 | +# Not yet ported to typing, but who knows |
| 610 | +if hasattr(typing, 'MappingAuxiliary'): |
| 611 | + MappingAuxiliary = typing.MappingAuxiliary |
| 612 | +else: |
| 613 | + class MappingAuxiliary(typing.Collection[KT_co], Protocol[KT_co, VT_co]): |
| 614 | + """Represents the covariant sub-protocol of the Mapping type. |
| 615 | + """ |
| 616 | + def items(self) -> ItemsView[KT_co, VT_co]: ... |
| 617 | + def keys(self) -> KeysView[KT_co]: ... |
| 618 | + def values(self) -> ValuesView[VT_co]: ... |
| 619 | + def __contains__(self, __o: object) -> bool: ... |
| 620 | + |
| 621 | + |
606 | 622 | # 3.8+ |
607 | 623 | if hasattr(typing, 'SupportsIndex'): |
608 | 624 | SupportsIndex = typing.SupportsIndex |
|
0 commit comments