Skip to content

Commit 37aa1fd

Browse files
author
Guido van Rossum
committed
Be explicit about type variables in generic container classes. See issue #85.
1 parent c4c67d3 commit 37aa1fd

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

prototyping/typing.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ class Iterable(Generic[T_co], extra=collections_abc.Iterable):
12401240
pass
12411241

12421242

1243-
class Iterator(Iterable, extra=collections_abc.Iterator):
1243+
class Iterator(Iterable[T_co], extra=collections_abc.Iterator):
12441244
pass
12451245

12461246

@@ -1303,7 +1303,7 @@ class Container(Generic[T_co], extra=collections_abc.Container):
13031303
# Callable was defined earlier.
13041304

13051305

1306-
class AbstractSet(Sized, Iterable, Container, extra=collections_abc.Set):
1306+
class AbstractSet(Sized, Iterable[T_co], Container[T_co], extra=collections_abc.Set):
13071307
pass
13081308

13091309

@@ -1320,7 +1320,7 @@ class MutableMapping(Mapping[KT, VT], extra=collections_abc.MutableMapping):
13201320
pass
13211321

13221322

1323-
class Sequence(Sized, Iterable, Container, extra=collections_abc.Sequence):
1323+
class Sequence(Sized, Iterable[T_co], Container[T_co], extra=collections_abc.Sequence):
13241324
pass
13251325

13261326

@@ -1347,7 +1347,7 @@ def __instancecheck__(self, obj):
13471347
return True
13481348

13491349

1350-
class List(list, MutableSequence, metaclass=_ListMeta):
1350+
class List(list, MutableSequence[T], metaclass=_ListMeta):
13511351

13521352
def __new__(self, *args, **kwds):
13531353
raise TypeError("Type List cannot be instantiated; use list() instead")
@@ -1365,7 +1365,7 @@ def __instancecheck__(self, obj):
13651365
return True
13661366

13671367

1368-
class Set(set, MutableSet, metaclass=_SetMeta):
1368+
class Set(set, MutableSet[T], metaclass=_SetMeta):
13691369

13701370
def __new__(self, *args, **kwds):
13711371
raise TypeError("Type Set cannot be instantiated; use set() instead")
@@ -1390,28 +1390,28 @@ def __instancecheck__(self, obj):
13901390
return super().__instancecheck__(obj)
13911391

13921392

1393-
class FrozenSet(frozenset, AbstractSet, metaclass=_FrozenSetMeta):
1393+
class FrozenSet(frozenset, AbstractSet[T_co], metaclass=_FrozenSetMeta):
13941394

13951395
def __new__(self, *args, **kwds):
13961396
raise TypeError("Type FrozenSet cannot be instantiated; "
13971397
"use frozenset() instead")
13981398

13991399

1400-
class MappingView(Sized, Iterable, extra=collections_abc.MappingView):
1400+
class MappingView(Sized, Iterable[T_co], extra=collections_abc.MappingView):
14011401
pass
14021402

14031403

1404-
class KeysView(MappingView, Set[KT], extra=collections_abc.KeysView):
1404+
class KeysView(MappingView[KT_co], AbstractSet[KT_co], extra=collections_abc.KeysView):
14051405
pass
14061406

14071407

1408-
# TODO: Enable Set[Tuple[KT, VT]] instead of Generic[KT, VT].
1408+
# TODO: Enable Set[Tuple[KT_co, VT_co]] instead of Generic[KT_co, VT_co].
14091409
class ItemsView(MappingView, Generic[KT_co, VT_co],
14101410
extra=collections_abc.ItemsView):
14111411
pass
14121412

14131413

1414-
class ValuesView(MappingView, extra=collections_abc.ValuesView):
1414+
class ValuesView(MappingView[VT_co], extra=collections_abc.ValuesView):
14151415
pass
14161416

14171417

@@ -1428,7 +1428,7 @@ def __instancecheck__(self, obj):
14281428
return True
14291429

14301430

1431-
class Dict(dict, MutableMapping, metaclass=_DictMeta):
1431+
class Dict(dict, MutableMapping[KT, VT], metaclass=_DictMeta):
14321432

14331433
def __new__(self, *args, **kwds):
14341434
raise TypeError("Type Dict cannot be instantiated; use dict() instead")

0 commit comments

Comments
 (0)