Skip to content

Commit 813fe5c

Browse files
committed
Address CR
1 parent 510b267 commit 813fe5c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pep-0484.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ elements. Example::
288288

289289
def notify_by_email(employees: Set[Employee], overrides: Mapping[str, str]) -> None: ...
290290

291-
Generics can be parametrized by using a new factory available in
291+
Generics can be parameterized by using a new factory available in
292292
``typing`` called ``TypeVar``. Example::
293293

294294
from typing import Sequence, TypeVar
@@ -611,9 +611,11 @@ the runtime class of the objects created by instantiating them doesn't
611611
record the distinction. This behavior is called "type erasure"; it is
612612
common practice in languages with generics (e.g. Java, TypeScript).
613613

614-
Class attribute of a generic class can be looked up only through the instance
615-
of the class; any attempt to use generic classes (parametrized or not) to
616-
access attributes will result in both type check failure and runtime error::
614+
Using generic classes (parameterized or not) to access attributes will result
615+
in both type check failure and runtime error. Outside the class definition
616+
body, a class attribute can only be looked up by accessing it through the
617+
class instance that does not have same-named instance attribute; it cannot be
618+
assigned at all::
617619

618620
# (continued from previous example)
619621
Node[int].x = 1 # Error
@@ -622,9 +624,10 @@ access attributes will result in both type check failure and runtime error::
622624
Node.x # Error
623625
type(p).x # Error
624626
p.x # Ok
627+
p.x = 1 # Will assign to instance attribute
625628
Node[int]().x # Ok
626629

627-
In addition, ``ClassVar`` cannot be parametrized.
630+
In addition, ``ClassVar`` cannot be parameterized.
628631

629632
Generic versions of abstract collections like ``Mapping`` or ``Sequence``
630633
and generic versions of built-in classes -- ``List``, ``Dict``, ``Set``,

0 commit comments

Comments
 (0)