diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-07-17 13:54:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-17 13:54:40 (GMT) |
commit | c6ef5aca614e3ee1cfe4125148d80e0e0bd77462 (patch) | |
tree | da9994575e53952e09cc2ade190c8e62b8940a43 /Lib/symtable.py | |
parent | 4395d68c7017eacf0ad643befe1f1e0bc6149f26 (diff) | |
download | cpython-c6ef5aca614e3ee1cfe4125148d80e0e0bd77462.zip cpython-c6ef5aca614e3ee1cfe4125148d80e0e0bd77462.tar.gz cpython-c6ef5aca614e3ee1cfe4125148d80e0e0bd77462.tar.bz2 |
[3.13] gh-119698: fix a special case in `symtable.Class.get_methods` (GH-121802) (#121909)
(cherry picked from commit 6682d916780c1cb305e679a057ee6992b114118e)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Lib/symtable.py')
-rw-r--r-- | Lib/symtable.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/symtable.py b/Lib/symtable.py index 73e9fb3..672ec0c 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -238,6 +238,11 @@ class Class(SymbolTable): if is_local_symbol(st.name): match st.type: case _symtable.TYPE_FUNCTION: + # generators are of type TYPE_FUNCTION with a ".0" + # parameter as a first parameter (which makes them + # distinguishable from a function named 'genexpr') + if st.name == 'genexpr' and '.0' in st.varnames: + continue d[st.name] = 1 case _symtable.TYPE_TYPE_PARAMETERS: # Get the function-def block in the annotation @@ -245,7 +250,14 @@ class Class(SymbolTable): scope_name = st.name for c in st.children: if c.name == scope_name and c.type == _symtable.TYPE_FUNCTION: - d[st.name] = 1 + # A generic generator of type TYPE_FUNCTION + # cannot be a direct child of 'st' (but it + # can be a descendant), e.g.: + # + # class A: + # type genexpr[genexpr] = (x for x in []) + assert scope_name != 'genexpr' or '.0' not in c.varnames + d[scope_name] = 1 break self.__methods = tuple(d) return self.__methods |