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:
Bénédikt Tran 2024-06-20 05:49:30 +02:00 committed by GitHub
parent 656a1c8108
commit b8a8e04fec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 186 additions and 5 deletions

View file

@ -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