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

Promote most dunder definitions on FunctionModel to ObjectModel #1519

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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__
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
attr___str__ = attr___ne__
attr___sizeof__ = attr___ne__
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
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