mirror of
https://github.com/python/cpython.git
synced 2025-08-26 19:55:24 +00:00
gh-119698: fix symtable.Class.get_methods
and document its behaviour correctly (#120151)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
656a1c8108
commit
b8a8e04fec
4 changed files with 186 additions and 5 deletions
|
@ -239,10 +239,25 @@ class Class(SymbolTable):
|
|||
"""
|
||||
if self.__methods is None:
|
||||
d = {}
|
||||
|
||||
def is_local_symbol(ident):
|
||||
flags = self._table.symbols.get(ident, 0)
|
||||
return ((flags >> SCOPE_OFF) & SCOPE_MASK) == LOCAL
|
||||
|
||||
for st in self._table.children:
|
||||
if st.type == _symtable.TYPE_ANNOTATION:
|
||||
continue
|
||||
d[st.name] = 1
|
||||
# pick the function-like symbols that are local identifiers
|
||||
if is_local_symbol(st.name):
|
||||
match st.type:
|
||||
case _symtable.TYPE_FUNCTION:
|
||||
d[st.name] = 1
|
||||
case _symtable.TYPE_TYPE_PARAM:
|
||||
# Get the function-def block in the annotation
|
||||
# scope 'st' with the same identifier, if any.
|
||||
scope_name = st.name
|
||||
for c in st.children:
|
||||
if c.name == scope_name and c.type == _symtable.TYPE_FUNCTION:
|
||||
d[st.name] = 1
|
||||
break
|
||||
self.__methods = tuple(d)
|
||||
return self.__methods
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue