1. Boris FELD
  2. pylint

Commits

Boris FELD  committed 48b21c7

Add test and code for #105298

  • Participants
  • Parent commits 68ba922
  • Branches default

Comments (0)

Files changed (5)

File checkers/typecheck.py

View file
  • Ignore whitespace
         elif (isinstance(called, astng.Function) or
               isinstance(called, astng.Lambda)):
             pass
+        elif isinstance(called, astng.Class):
+            method = called.lookup('__init__')[1]
+            if len(method) == 1:
+                called = method[0]
+                # __init__ method have an extra implicit 'self' argument.
+                num_positional_args += 1
+            else:
+                #XXX deal with default class constructor (no params)
+                return
+        elif isinstance(called, astng.Instance) and called.callable():
+            called = called.getattr('__call__')[0]
+            num_positional_args += 1
         else:
             return
 

File test/input/func_class_init_parameters.py

View file
  • Ignore whitespace
+# pylint:disable=C0111, C0103, R0903, W0232, C0301, W0511
+"""Checks that class init parameters are correctly detected !
+"""
+__revision__ = ''
+
+class TestClass:
+    pass
+
+class TestClass2:
+    def __init__(self, param):
+        pass
+
+class TestClass3:
+    def __init__(self):
+        pass
+
+class C:
+    def c(self, param1, param2, param3):
+        pass
+
+a = TestClass()
+a = TestClass('hello') # XXX Add warning for calling object.__init__ with parameters?
+b = TestClass2() # Error
+b = TestClass2('hello')
+c = TestClass3()
+c = TestClass3('hello') # Error

File test/input/func_instance_call_parameters.py

View file
  • Ignore whitespace
+# pylint:disable=C0111,
+__revision__ = ''
+class Logger:
+    def __init__(self):
+        pass
+    def __call__(self, msg):
+        pass
+
+LOG = Logger()
+LOG('bonjour')
+LOG() # Error
+LOG('bon', 'jour') # Error

File test/messages/func_class_init_parameters.txt

View file
  • Ignore whitespace
+E: 23: No value passed for parameter 'param' in function call
+E: 26: Too many positional arguments for function call

File test/messages/func_instance_call_parameters.txt

View file
  • Ignore whitespace
+E: 11: No value passed for parameter 'msg' in function call
+E: 12: Too many positional arguments for function call