Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable AsyncGeneratorModel from inheriting Generator attributes #2587

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading