PEP 526: Name mangling doesn't take place inside the body of a module
Nessuno ha ancora preso questa issue.
- Lingua principale
- reStructuredText
- Stelle
- 5k
- Fork
- 1.8k
- Merge medio
- 2g 4h
- PR unite (30g)
- 25
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Apri PEP 526 e rivedi la sezione “Runtime Effects of Type Annotations”, in particolare il relativo esempio di annotazione a livello di modulo e l'output visualizzato. Conferma il comportamento di name-mangling rispetto all'esempio, quindi aggiorna il codice o l'output in modo che concordino e mantengano una dimostrazione chiara del mangling a livello di classe. Il lavoro è concluso quando il PEP renderizzato non presenta più risultati contraddittori.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 55/100