Skip to content

Commit 995e3ff

Browse files
committed
Promote most dunder definitions on FunctionModel to ObjectModel
1 parent 9224558 commit 995e3ff

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

astroid/interpreter/objectmodel.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,28 @@ def attr___init__(self) -> bases.BoundMethod:
155155

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

158+
# These are here just for completion.
159+
@property
160+
def attr___ne__(self):
161+
return node_classes.Unknown()
162+
163+
attr___subclasshook__ = attr___ne__
164+
attr___str__ = attr___ne__
165+
attr___sizeof__ = attr___ne__
166+
attr___setattr___ = attr___ne__
167+
attr___repr__ = attr___ne__
168+
attr___reduce__ = attr___ne__
169+
attr___reduce_ex__ = attr___ne__
170+
attr___lt__ = attr___ne__
171+
attr___eq__ = attr___ne__
172+
attr___gt__ = attr___ne__
173+
attr___format__ = attr___ne__
174+
attr___delattr___ = attr___ne__
175+
attr___getattribute__ = attr___ne__
176+
attr___hash__ = attr___ne__
177+
attr___dir__ = attr___ne__
178+
attr___class__ = attr___ne__
179+
158180

159181
class ModuleModel(ObjectModel):
160182
def _builtins(self):
@@ -412,29 +434,9 @@ def test(self):
412434
return DescriptorBoundMethod(proxy=self._instance, bound=self._instance)
413435

414436
# These are here just for completion.
415-
@property
416-
def attr___ne__(self):
417-
return node_classes.Unknown()
418-
419-
attr___subclasshook__ = attr___ne__
420-
attr___str__ = attr___ne__
421-
attr___sizeof__ = attr___ne__
422-
attr___setattr___ = attr___ne__
423-
attr___repr__ = attr___ne__
424-
attr___reduce__ = attr___ne__
425-
attr___reduce_ex__ = attr___ne__
426-
attr___lt__ = attr___ne__
427-
attr___eq__ = attr___ne__
428-
attr___gt__ = attr___ne__
429-
attr___format__ = attr___ne__
430-
attr___delattr___ = attr___ne__
431-
attr___getattribute__ = attr___ne__
432-
attr___hash__ = attr___ne__
433-
attr___dir__ = attr___ne__
434-
attr___call__ = attr___ne__
435-
attr___class__ = attr___ne__
436-
attr___closure__ = attr___ne__
437-
attr___code__ = attr___ne__
437+
attr___call__ = ObjectModel.attr___ne__
438+
attr___closure__ = ObjectModel.attr___ne__
439+
attr___code__ = ObjectModel.attr___ne__
438440

439441

440442
class ClassModel(ObjectModel):

tests/unittest_object_model.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ def test_module_model(self) -> None:
262262
xml.__repr__ #@
263263
xml.__reduce__ #@
264264
265-
xml.__setattr__ #@
266265
xml.__reduce_ex__ #@
267266
xml.__lt__ #@
268267
xml.__eq__ #@
@@ -272,6 +271,8 @@ def test_module_model(self) -> None:
272271
xml.__getattribute__ #@
273272
xml.__hash__ #@
274273
xml.__dir__ #@
274+
275+
xml.__setattr__ #@
275276
xml.__call__ #@
276277
xml.__closure__ #@
277278
"""
@@ -316,9 +317,13 @@ def test_module_model(self) -> None:
316317

317318
# The following nodes are just here for theoretical completeness,
318319
# and they either return Uninferable or raise InferenceError.
319-
for ast_node in ast_nodes[11:28]:
320+
for ast_node in ast_nodes[11:25]:
321+
inferred = next(ast_node.infer())
322+
assert inferred is util.Uninferable
323+
324+
for ast_node in ast_nodes[25:28]:
320325
with pytest.raises(InferenceError):
321-
next(ast_node.infer())
326+
inferred = next(ast_node.infer())
322327

323328

324329
class FunctionModelTest(unittest.TestCase):

0 commit comments

Comments
 (0)