Skip to content

Commit b166c5e

Browse files
committed
Suppress false-positive not-callable messages from class descriptors
This is a holdover until astroid can be fixed. Astroid needs to understand descriptors or at least raise Uninferable instead of allowing the descriptor instance through Close #1699
1 parent 2f77413 commit b166c5e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pylint/checkers/typecheck.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,12 @@ def visit_call(self, node):
875875

876876
called = safe_infer(node.func)
877877
# only function, generator and object defining __call__ are allowed
878+
# Ignore instances of descriptors since astroid cannot properly handle them
879+
# yet
878880
if called and not called.callable():
879-
if isinstance(called, astroid.Instance) and not has_known_bases(called):
881+
if isinstance(called, astroid.Instance) and (not has_known_bases(called)
882+
or (isinstance(called.scope(), astroid.ClassDef)
883+
and '__get__' in called.locals)):
880884
# Don't emit if we can't make sure this object is callable.
881885
pass
882886
else:

pylint/test/unittest_checker_typecheck.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,19 @@ def test_typing_namedtuple_unsubscriptable_object_issue1295(self):
229229
subscript = module.body[-1].value
230230
with self.assertNoMessages():
231231
self.checker.visit_subscript(subscript)
232+
233+
def test_staticmethod_multiprocessing_call(self):
234+
"""Make sure not-callable isn't raised for descriptors
235+
236+
astroid can't process descriptors correctly so
237+
pylint needs to ignore not-callable for them
238+
right now
239+
240+
Test for https://github.com/PyCQA/pylint/issues/1699
241+
"""
242+
call = astroid.extract_node("""
243+
import multiprocessing
244+
multiprocessing.current_process() #@
245+
""")
246+
with self.assertNoMessages():
247+
self.checker.visit_call(call)

0 commit comments

Comments
 (0)