Skip to content

Commit

Permalink
disable AsyncGeneratorModel from inheriting Generator attributes
Browse files Browse the repository at this point in the history
for example, usual generators have "send", but async don't. They have
   "async" instead.
  • Loading branch information
temyurchenko authored and DanielNoord committed Sep 30, 2024
1 parent 62c5bad commit f19fc0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ class Generator(BaseInstance):
# We defer initialization of special_attributes to the __init__ method since the constructor
# of GeneratorModel requires the raw_building to be complete
# TODO: This should probably be refactored.
special_attributes: objectmodel.GeneratorModel
special_attributes: objectmodel.GeneratorBaseModel

def __init__(
self,
Expand Down
25 changes: 8 additions & 17 deletions astroid/interpreter/objectmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,10 @@ def attr___self__(self):
return self._instance.bound


class GeneratorModel(FunctionModel, ContextManagerModel):
def __init__(self):
# Append the values from the GeneratorType unto this object.
class GeneratorBaseModel(FunctionModel, ContextManagerModel):
def __init__(self, gen_module: nodes.Module):
super().__init__()
generator = AstroidManager().builtins_module["generator"]
for name, values in generator.locals.items():
for name, values in gen_module.locals.items():
method = values[0]
if isinstance(method, nodes.FunctionDef):
method = bases.BoundMethod(method, _get_bound_node(self))
Expand All @@ -723,21 +721,14 @@ def attr___doc__(self):
)


class AsyncGeneratorModel(GeneratorModel):
class GeneratorModel(GeneratorBaseModel):
def __init__(self):
# Append the values from the AGeneratorType unto this object.
super().__init__()
astroid_builtins = AstroidManager().builtins_module
generator = astroid_builtins["async_generator"]
for name, values in generator.locals.items():
method = values[0]
if isinstance(method, nodes.FunctionDef):
method = bases.BoundMethod(method, _get_bound_node(self))
super().__init__(AstroidManager().builtins_module["generator"])

def patched(cls, meth=method):
return meth

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


class InstanceModel(ObjectModel):
Expand Down

0 comments on commit f19fc0a

Please sign in to comment.