Skip to content

Commit

Permalink
Promote most dunder definitions on FunctionModel to ObjectModel
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Feb 5, 2023
1 parent ac41d4e commit a235a71
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
48 changes: 25 additions & 23 deletions astroid/interpreter/objectmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,28 @@ def attr___init__(self) -> bases.BoundMethod:

return bases.BoundMethod(proxy=node, bound=_get_bound_node(self))

# These are here just for completion.
@property
def attr___ne__(self):
return node_classes.Unknown()

attr___subclasshook__ = attr___ne__
attr___str__ = attr___ne__
attr___sizeof__ = attr___ne__
attr___setattr___ = attr___ne__
attr___repr__ = attr___ne__
attr___reduce__ = attr___ne__
attr___reduce_ex__ = attr___ne__
attr___lt__ = attr___ne__
attr___eq__ = attr___ne__
attr___gt__ = attr___ne__
attr___format__ = attr___ne__
attr___delattr___ = attr___ne__
attr___getattribute__ = attr___ne__
attr___hash__ = attr___ne__
attr___dir__ = attr___ne__
attr___class__ = attr___ne__


class ModuleModel(ObjectModel):
def _builtins(self):
Expand Down Expand Up @@ -422,29 +444,9 @@ def test(self):
return DescriptorBoundMethod(proxy=self._instance, bound=self._instance)

# These are here just for completion.
@property
def attr___ne__(self):
return node_classes.Unknown()

attr___subclasshook__ = attr___ne__
attr___str__ = attr___ne__
attr___sizeof__ = attr___ne__
attr___setattr___ = attr___ne__
attr___repr__ = attr___ne__
attr___reduce__ = attr___ne__
attr___reduce_ex__ = attr___ne__
attr___lt__ = attr___ne__
attr___eq__ = attr___ne__
attr___gt__ = attr___ne__
attr___format__ = attr___ne__
attr___delattr___ = attr___ne__
attr___getattribute__ = attr___ne__
attr___hash__ = attr___ne__
attr___dir__ = attr___ne__
attr___call__ = attr___ne__
attr___class__ = attr___ne__
attr___closure__ = attr___ne__
attr___code__ = attr___ne__
attr___call__ = ObjectModel.attr___ne__
attr___closure__ = ObjectModel.attr___ne__
attr___code__ = ObjectModel.attr___ne__


class ClassModel(ObjectModel):
Expand Down
11 changes: 8 additions & 3 deletions tests/unittest_object_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ def test_module_model(self) -> None:
xml.__repr__ #@
xml.__reduce__ #@
xml.__setattr__ #@
xml.__reduce_ex__ #@
xml.__lt__ #@
xml.__eq__ #@
Expand All @@ -272,6 +271,8 @@ def test_module_model(self) -> None:
xml.__getattribute__ #@
xml.__hash__ #@
xml.__dir__ #@
xml.__setattr__ #@
xml.__call__ #@
xml.__closure__ #@
"""
Expand Down Expand Up @@ -316,9 +317,13 @@ def test_module_model(self) -> None:

# The following nodes are just here for theoretical completeness,
# and they either return Uninferable or raise InferenceError.
for ast_node in ast_nodes[11:28]:
for ast_node in ast_nodes[11:25]:
inferred = next(ast_node.infer())
assert inferred is util.Uninferable

for ast_node in ast_nodes[25:28]:
with pytest.raises(InferenceError):
next(ast_node.infer())
inferred = next(ast_node.infer())


class FunctionModelTest(unittest.TestCase):
Expand Down

0 comments on commit a235a71

Please sign in to comment.