Skip to content

Commit f19fc0a

Browse files
temyurchenkoDanielNoord
authored andcommitted
disable AsyncGeneratorModel from inheriting Generator attributes
for example, usual generators have "send", but async don't. They have "async" instead.
1 parent 62c5bad commit f19fc0a

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

astroid/bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ class Generator(BaseInstance):
679679
# We defer initialization of special_attributes to the __init__ method since the constructor
680680
# of GeneratorModel requires the raw_building to be complete
681681
# TODO: This should probably be refactored.
682-
special_attributes: objectmodel.GeneratorModel
682+
special_attributes: objectmodel.GeneratorBaseModel
683683

684684
def __init__(
685685
self,

astroid/interpreter/objectmodel.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,10 @@ def attr___self__(self):
694694
return self._instance.bound
695695

696696

697-
class GeneratorModel(FunctionModel, ContextManagerModel):
698-
def __init__(self):
699-
# Append the values from the GeneratorType unto this object.
697+
class GeneratorBaseModel(FunctionModel, ContextManagerModel):
698+
def __init__(self, gen_module: nodes.Module):
700699
super().__init__()
701-
generator = AstroidManager().builtins_module["generator"]
702-
for name, values in generator.locals.items():
700+
for name, values in gen_module.locals.items():
703701
method = values[0]
704702
if isinstance(method, nodes.FunctionDef):
705703
method = bases.BoundMethod(method, _get_bound_node(self))
@@ -723,21 +721,14 @@ def attr___doc__(self):
723721
)
724722

725723

726-
class AsyncGeneratorModel(GeneratorModel):
724+
class GeneratorModel(GeneratorBaseModel):
727725
def __init__(self):
728-
# Append the values from the AGeneratorType unto this object.
729-
super().__init__()
730-
astroid_builtins = AstroidManager().builtins_module
731-
generator = astroid_builtins["async_generator"]
732-
for name, values in generator.locals.items():
733-
method = values[0]
734-
if isinstance(method, nodes.FunctionDef):
735-
method = bases.BoundMethod(method, _get_bound_node(self))
726+
super().__init__(AstroidManager().builtins_module["generator"])
736727

737-
def patched(cls, meth=method):
738-
return meth
739728

740-
setattr(type(self), IMPL_PREFIX + name, property(patched))
729+
class AsyncGeneratorModel(GeneratorBaseModel):
730+
def __init__(self):
731+
super().__init__(AstroidManager().builtins_module["async_generator"])
741732

742733

743734
class InstanceModel(ObjectModel):

0 commit comments

Comments
 (0)