Hi,
In PEP 526, there is a section called "Runtime Effects of Type Annotations" which has the following code:
from typing import Dict
class Player:
...
players: Dict[str, Player]
__points: int
print(__annotations__)
# prints: {'players': typing.Dict[str, __main__.Player],
# '_Player__points': <class 'int'>}
The code and the output don't match.
Name mangling only happens inside the body of the class not module. So the correct output would be:
{'players': typing.Dict[str, __main__.Player], '__points': <class 'int'>}
If we want to see the effect of name mangling we could have something like:
from typing import Dict
class Player:
__points: int
players: Dict[str, Player]
print(__annotations__)
print(Player.__annotations__)
Or have the print(__annotations__) inside the class:
from typing import Dict
class Player:
__points: int
print(__annotations__)
players: Dict[str, Player]
print(__annotations__)
That would be a quick fix if you confirm.
Hi,
In PEP 526, there is a section called "Runtime Effects of Type Annotations" which has the following code:
The code and the output don't match.
Name mangling only happens inside the body of the class not module. So the correct output would be:
If we want to see the effect of name mangling we could have something like:
Or have the
print(__annotations__)inside the class:That would be a quick fix if you confirm.