Skip to content

Commit e03cf3e

Browse files
authored
PEP 526: Fix name mangling example (#5138)
Name mangling only applies inside a class body, so a module-level ``__points: int`` is stored as ``'__points'``, not ``'_Player__points'``. Move the annotation into the class and print its ``__annotations__``.
1 parent 7d5ca36 commit e03cf3e

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎peps/pep-0526.rst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,13 @@ Here is an example::
438438

439439
from typing import Dict
440440
class Player:
441-
...
441+
__points: int
442442
players: Dict[str, Player]
443-
__points: int
444443

445444
print(__annotations__)
446-
# prints: {'players': typing.Dict[str, __main__.Player],
447-
# '_Player__points': <class 'int'>}
445+
# prints: {'players': typing.Dict[str, __main__.Player]}
446+
print(Player.__annotations__)
447+
# prints: {'_Player__points': <class 'int'>}
448448

449449
``__annotations__`` is writable, so this is permitted::
450450

0 commit comments

Comments
 (0)