Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62d2d6d

Browse files
committed
prepare for handling PEP 649
1 parent 1352d08 commit 62d2d6d

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

Lib/symtable.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
DEF_GLOBAL, DEF_NONLOCAL, DEF_LOCAL,
77
DEF_PARAM, DEF_TYPE_PARAM, DEF_IMPORT, DEF_BOUND, DEF_ANNOT,
88
SCOPE_OFF, SCOPE_MASK,
9-
FREE, LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL
9+
FREE, LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL,
1010
)
1111

1212
import weakref
@@ -229,19 +229,17 @@ def is_local_symbol(ident):
229229
for st in self._table.children:
230230
# pick the function-like symbols that are local identifiers
231231
if is_local_symbol(st.name):
232-
if st.type == _symtable.TYPE_TYPE_PARAM:
233-
# Current 'st' is an annotation scope with one or
234-
# more children (we expect only one, but we might
235-
# have more in the future). In particular, we need
236-
# to find the corresponding inner function, class or
237-
# type alias.
238-
st = next((c for c in st.children if c.name == st.name), None)
239-
# if 'st' is None, then the annotation scopes are broken
240-
assert st is not None, 'annotation scopes are broken'
241-
242-
# only select function-like symbols
243-
if st.type == _symtable.TYPE_FUNCTION:
244-
d[st.name] = 1
232+
match st.type:
233+
case _symtable.TYPE_FUNCTION:
234+
d[st.name] = 1
235+
case _symtable.TYPE_TYPE_PARAM:
236+
# Get the function-def block in the annotation
237+
# scope 'st' with the same identifier, if any.
238+
scope_name = st.name
239+
for c in st.children:
240+
if c.name == scope_name and c.type == _symtable.TYPE_FUNCTION:
241+
d[st.name] = 1
242+
break
245243
self.__methods = tuple(d)
246244
return self.__methods
247245

0 commit comments

Comments
 (0)