Skip to content

Commit a235a71

Browse files
committed
Promote most dunder definitions on FunctionModel to ObjectModel
1 parent ac41d4e commit a235a71

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
@@ -161,6 +161,28 @@ def attr___init__(self) -> bases.BoundMethod:
161161

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

164+
# These are here just for completion.
165+
@property
166+
def attr___ne__(self):
167+
return node_classes.Unknown()
168+
169+
attr___subclasshook__ = attr___ne__
170+
attr___str__ = attr___ne__
171+
attr___sizeof__ = attr___ne__
172+
attr___setattr___ = attr___ne__
173+
attr___repr__ = attr___ne__
174+
attr___reduce__ = attr___ne__
175+
attr___reduce_ex__ = attr___ne__
176+
attr___lt__ = attr___ne__
177+
attr___eq__ = attr___ne__
178+
attr___gt__ = attr___ne__
179+
attr___format__ = attr___ne__
180+
attr___delattr___ = attr___ne__
181+
attr___getattribute__ = attr___ne__
182+
attr___hash__ = attr___ne__
183+
attr___dir__ = attr___ne__
184+
attr___class__ = attr___ne__
185+
164186

165187
class ModuleModel(ObjectModel):
166188
def _builtins(self):
@@ -422,29 +444,9 @@ def test(self):
422444
return DescriptorBoundMethod(proxy=self._instance, bound=self._instance)
423445

424446
# These are here just for completion.
425-
@property
426-
def attr___ne__(self):
427-
return node_classes.Unknown()
428-
429-
attr___subclasshook__ = attr___ne__
430-
attr___str__ = attr___ne__
431-
attr___sizeof__ = attr___ne__
432-
attr___setattr___ = attr___ne__
433-
attr___repr__ = attr___ne__
434-
attr___reduce__ = attr___ne__
435-
attr___reduce_ex__ = attr___ne__
436-
attr___lt__ = attr___ne__
437-
attr___eq__ = attr___ne__
438-
attr___gt__ = attr___ne__
439-
attr___format__ = attr___ne__
440-
attr___delattr___ = attr___ne__
441-
attr___getattribute__ = attr___ne__
442-
attr___hash__ = attr___ne__
443-
attr___dir__ = attr___ne__
444-
attr___call__ = attr___ne__
445-
attr___class__ = attr___ne__
446-
attr___closure__ = attr___ne__
447-
attr___code__ = attr___ne__
447+
attr___call__ = ObjectModel.attr___ne__
448+
attr___closure__ = ObjectModel.attr___ne__
449+
attr___code__ = ObjectModel.attr___ne__
448450

449451

450452
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)