org.sonar.l10n.py.rules.python.S5756.html Maven / Gradle / Ivy
This rule raises an issue when a call is made to a non-callable object.
Why is this an issue?
In order to be callable, a Python class should implement the __call__
method. Thanks to this method, an instance of this
class will be callable as a function.
However, when making a call to a non-callable object, a TypeError
will be raised.
In order to fix this issue, make sure that the object you are trying to call has a __call__
method.
Code examples
Noncompliant code example
class MyClass:
pass
myvar = MyClass()
myvar() # Noncompliant
none_var = None
none_var() # Noncompliant
Compliant solution
class MyClass:
def __call__(self):
print("called")
myvar = MyClass()
myvar()
Resources
Documentation
© 2015 - 2024 Weber Informatics LLC | Privacy Policy