Can override ignoring local imports in modules by using __all__

This commit is contained in:
Ashley Whetter 2019-06-23 12:36:58 -07:00
parent 9d45eed4d0
commit 589826e90c
5 changed files with 27 additions and 3 deletions

View File

@ -27,6 +27,7 @@ class PythonPythonMapper(PythonMapperBase):
self.children = []
self.args = obj.get("args")
self.docstring = obj["doc"]
self.imported = "original_path" in obj
# For later
self._class_content = class_content

View File

@ -221,7 +221,7 @@ class Parser(object):
top_name = node.name.split(".", 1)[0]
for child in node.get_children():
if node.package and astroid_utils.is_local_import_from(child, top_name):
if astroid_utils.is_local_import_from(child, top_name):
child_data = self._parse_local_import_from(child)
else:
child_data = self.parse(child)

View File

@ -47,7 +47,13 @@ Submodules
{% endif %}
{% endblock %}
{% block content %}
{% if obj.all is not none %}
{% set visible_children = obj.children|selectattr("short_name", "in", obj.all)|list %}
{% elif obj.type is equalto("package") %}
{% set visible_children = obj.children|selectattr("display")|list %}
{% else %}
{% set visible_children = obj.children|selectattr("display")|rejectattr("imported")|list %}
{% endif %}
{% if visible_children %}
{{ obj.type|title }} Contents
{{ "-" * obj.type|length }}---------
@ -86,9 +92,7 @@ Functions
{% endblock %}
{% endif %}
{% for obj_item in visible_children %}
{% if obj.all is none or obj_item.short_name in obj.all %}
{{ obj_item.rendered|indent(0) }}
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}

View File

@ -3,6 +3,11 @@
This is a description
"""
from ._private_module import PrivateClass as PublicClass
from ._subpackage import module_level_method
__all__ = ["PublicClass", "Foo"]
class Foo(object):

View File

@ -370,3 +370,17 @@ class TestComplexPackage(object):
assert "simple_function" in wildcard_file
assert "public_chain" in wildcard_file
assert "module_level_method" in wildcard_file
def test_no_imports_in_module_with_all(self):
foo_path = "_build/text/autoapi/complex/foo/index.txt"
with io.open(foo_path, encoding="utf8") as foo_handle:
foo_file = foo_handle.read()
assert "module_level_method" not in foo_file
def test_all_overrides_import_in_module_with_all(self):
foo_path = "_build/text/autoapi/complex/foo/index.txt"
with io.open(foo_path, encoding="utf8") as foo_handle:
foo_file = foo_handle.read()
assert "PublicClass" in foo_file