[3.12] gh-119698: fix symtable.Class.get_methods and document its behaviour correctly (#120151) (#120776)

(cherry picked from commit b8a8e04fec)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Jelle Zijlstra 2024-06-19 22:12:31 -07:00 committed by GitHub
parent 61e37dd4f5
commit 0c6d6ab252
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 186 additions and 3 deletions

View file

@ -217,8 +217,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:
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