diff --git a/astroid/bases.py b/astroid/bases.py index 7611a77c0d..d91a4c9faf 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -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, diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py index 7532db5edb..fd8c0c051b 100644 --- a/astroid/interpreter/objectmodel.py +++ b/astroid/interpreter/objectmodel.py @@ -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)) @@ -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):