All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S5807.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

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