Undefined name detected in `__all__`PYL-E0603
__all__
is a list of strings defining what objects in a module will be exported when from <module> import *
is used on the module.
Hence, all the object names mentioned in __all__
shall be defined in the module.
This issue is raised because __all__
contains atleast one name (See issue title for the exact name) which is not defined in the module.
When a wildcard import is attempted on the module with this guilty code, Python will throw an AttributeError
while trying to import the undefined object.
Here is an example:
guilty.py
def my_awesome_function():
print("This is my awesome function.")
__all__ = ["my_awesome_function", "something_undefined"]
foo.py
from guilty import *
my_awesome_function()
When foo.py
is run, Python will throw this error:
AttributeError: module 'guilty' has no attribute 'something_undefined'
Note: During autofixing this issue, DeepSource will remove all the undefined name. If the there's a missing comma which implicitly concatenate the names, DeepSource will separate all the concatenated strings.
Bad practice
In the following snippet, connection
and frame
is undefined.
There's also a missing comma between predict
and "ClearMap".
...
__all__ = ["connection", "predict" "ClearMap", "frame"]
Recommended
The autofix will remove undefined connection
and frame
and add a comma between predict
and "ClearMap".
...
__all__ = ["predict", "ClearMap"]