|
6 | 6 | DEF_GLOBAL, DEF_NONLOCAL, DEF_LOCAL,
|
7 | 7 | DEF_PARAM, DEF_TYPE_PARAM, DEF_IMPORT, DEF_BOUND, DEF_ANNOT,
|
8 | 8 | SCOPE_OFF, SCOPE_MASK,
|
9 |
| - FREE, LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL |
| 9 | + FREE, LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL, |
10 | 10 | )
|
11 | 11 |
|
12 | 12 | import weakref
|
@@ -229,19 +229,17 @@ def is_local_symbol(ident):
|
229 | 229 | for st in self._table.children:
|
230 | 230 | # pick the function-like symbols that are local identifiers
|
231 | 231 | 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 |
245 | 243 | self.__methods = tuple(d)
|
246 | 244 | return self.__methods
|
247 | 245 |
|
|
0 commit comments