library symtable.SymbolTable.is_nested() description differs from Cpython implementation.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 558
Beschreibung
The documentation says
is_nested()
Return True if the block is a nested class or function.
The cpython implementation of symtable.c sets the corresponding flag only if the block is nested somewhere inside a function. This would include, for example, a scope inside a class inside a function.
Thus
def f(): # false
def g(): # true
def h(): # true
class C: # true
class B: # true
def h(): # true
class C: # true
class A: # false
def g(): # false !!
def h(): # true
class C: # true
class B: # false !!
def h(): # false !!
class C: # false !!
The value is the same as the CO_NESTED bit in the code object's co_flags member.
The flag is also documented (similarly incorrectly) in the inspect module documentation.
I would recommend deprecating this feature. The documentation for co_flags says that
bits 0x10 and 0x1000 were used in earlier versions of Python.
0x10 is the CO_NESTED bit. I would guess that nobody uses CO_NESTED or SymbolTable.is_nested().
Alternatives:
- Change the behavior in Cpython to agree with the documentation. A class nested in another scope should also have CO_NESTED set. Make a test case for the compiler, to ensure that other implementations follow the same definition.
- Correct the documentation for symtable and inspect modules. Possibly also deprecate the feature.
Linked PRs
- gh-151901
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
Überprüfe zuerst den verlinkten PR gh-151901, vergleiche anschließend die symtable und prüfe die Dokumentation anhand des angegebenen CPython-Verhaltens und des CO_NESTED-Flags. Das Issue lässt die Lösung offen: Entweder die Implementierung angleichen und compiler tests hinzufügen oder die Dokumentation korrigieren und das Feature möglicherweise als veraltet markieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 20/100