deadcode icon indicating copy to clipboard operation
deadcode copied to clipboard

Wildcard import expression should only import items provided in `__all__` iterable.

Open albertas opened this issue 1 year ago • 0 comments

By default wildcard import imports all the names, which do not start with underscore. However, it is possible to limit names, which might be imported by defining __all__ variable in the module. Only items listed in __all__ variable can be imported from this module.

This should be reflected in the behavior of deadcode.

Example: foo.py

__all__ = ['foo', 'bar']

foo = 1
bar = 2
spam = 3

bar.py

from foo import *

print(foo)
print(bar)

# Should raise an error, because `spam` was not imported:
print(spam)

albertas avatar Jul 11 '24 05:07 albertas