27 lines
647 B
Plaintext
27 lines
647 B
Plaintext
Developers may define a list named ``++__all__++`` in a module to limit the names imported from it by wildcard imports (``++from mymodule import *++``). This list can only reference defined names, otherwise an ``++AttributeError++`` will be raised when the module is imported.
|
|
|
|
|
|
== 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"]
|
|
----
|
|
|
|
|
|
== See
|
|
|
|
* https://docs.python.org/3/tutorial/modules.html#importing-from-a-package[Python documentation - Importing * From a Package]
|
|
|
|
|