org.sonar.l10n.py.rules.python.S5807.html Maven / Gradle / Ivy
This rule raises an issue when a name listed in the __all__
property of a module has not been defined.
Why is this an issue?
The __all__
property of a module is used to define the list of names that will be imported when performing a wildcard import of this
module, i.e. when from mymodule import *
is used.
In the following example:
# mymodule.py
def foo(): ...
def bar(): ...
__all__ = ["foo"]
Executing from mymodule import *
from a different module will only import foo
.
This list can only reference defined names, otherwise an AttributeError
will be raised when the module is imported.
Code examples
Noncompliant code example
from mymodule import my_func
__all__ = ["unknown_func"] # Noncompliant: "unknown_func" is undefined
Compliant solution
from mymodule import my_func
__all__ = ["my_func"]
Resources
Documentation
© 2015 - 2024 Weber Informatics LLC | Privacy Policy