rspec/rules/S5807/python/rule.adoc

48 lines
995 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,python]
2021-04-28 16:49:39 +02:00
----
from mymodule import my_func
__all__ = ["unknown_func"] # Noncompliant. "unknown_func" is undefined
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,python]
2021-04-28 16:49:39 +02:00
----
from mymodule import my_func
__all__ = ["my_func"]
----
== Resources
2021-04-28 16:49:39 +02:00
* https://docs.python.org/3/tutorial/modules.html#importing-from-a-package[Python documentation - Importing * From a Package]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]