PEP 526: Name mangling doesn't take place inside the body of a module
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- reStructuredText
- Sterne
- 5k
- Forks
- 1.8k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 25
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Öffne PEP 526 und überprüfe den Abschnitt “Runtime Effects of Type Annotations”, insbesondere sein Beispiel für Annotationen auf Modulebene und die angezeigte Ausgabe. Bestätige das Name-Mangling-Verhalten anhand des Beispiels und aktualisiere dann den Code oder die Ausgabe, sodass sie übereinstimmen und weiterhin eine klare Demonstration des Manglings auf Klassenebene erhalten bleibt. Die Aufgabe ist erledigt, wenn das gerenderte PEP keine widersprüchlichen Ergebnisse mehr präsentiert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- Unter einer Stunde
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 55/100