mirror of
https://github.com/python/cpython.git
synced 2025-08-10 11:58:39 +00:00
[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:
parent
61e37dd4f5
commit
0c6d6ab252
4 changed files with 186 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue