Skip to content

Commit 92b5b19

Browse files
author
Guido van Rossum
committed
Typos, rst formatting and a minor addition to PEP 483 (Ivan L, upstream #227)
1 parent ac8459d commit 92b5b19

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pep-0483.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ the runtime classes.* Examples:
261261

262262
Typing interface is implemented with classes, i.e., at runtime it is possible
263263
to evaluate, e.g., ``Generic[T].__bases__``. But to emphasize the distinction
264-
between classes and types the following general rules:
264+
between classes and types the following general rules apply:
265265

266266
- No types defined below (i.e. ``Any``, ``Union``, etc.) can be instantiated,
267267
an attempt to do so will raise ``TypeError``.
@@ -496,8 +496,8 @@ Defining and using generic types
496496
--------------------------------
497497

498498
Users can declare their classes as generic types using
499-
the special building block ``Generic``.
500-
``class MyGeneric(Generic[X, Y, ...]): ... `` defines a generic type
499+
the special building block ``Generic``. The definition
500+
``class MyGeneric(Generic[X, Y, ...]): ...`` defines a generic type
501501
``MyGeneric`` over type variables ``X``, etc. ``MyGeneric`` itself becomes
502502
parameterizable, e.g. ``MyGeneric[int, str, ...]`` is a specific type with
503503
substitutions ``X -> int``, etc. Example::
@@ -531,6 +531,10 @@ not generic. Examples::
531531
def search(urls: URLList) -> Optional[bytes] # URLList is not generic
532532
...
533533

534+
Subclassing a generic type imposes the subtype relation on the corresponding
535+
specific types, so that ``TodoList[t1]`` is a subtype of ``Iterable[t1]``
536+
in the above example.
537+
534538
Generic types can be specialized (indexed) in several steps.
535539
Every type variable could be substituted by a specific type
536540
or by another generic type. If ``Generic`` appears in the base class list,
@@ -677,7 +681,8 @@ Types are invariant by default. Examples::
677681

678682
class Sink(Generic[T_contra]): # this type is declared contravariant
679683
def send_to_nowhere(self, data: T_contra) -> None:
680-
print(data, file=os.devnull)
684+
with open(os.devnull, 'w') as devnull:
685+
print(data, file=devnull)
681686

682687
Note, that although the variance is defined via type variables, it is not
683688
a property of type variables, but a property of generic types.

0 commit comments

Comments
 (0)