Skip to content

Wrong namespace resolution for base clases when using star importΒ #404

Open
@jorgepiloto

Description

@jorgepiloto

The issue 🐞

Consider the following project:

.
β”œβ”€β”€ package/
β”‚   β”œβ”€β”€__init__.py
β”‚Β Β  β”œβ”€β”€ module_A.py
β”‚Β Β  └── module_B.py
β”œβ”€β”€ conf.py
└── index.rst

The content of each file:

module_A.py module_B.py index.rst conf.py
from enum import IntEnum

from .module_B import *

__all__ = ["FooA"]

class FooA(IntEnum):
    ITEM_0 = 0
    ITEM_1 = 1
    ITEM_2 = 2
from enum import IntEnum

__all__ = ["FooB"]

class FooB(IntEnum):
    ITEM_0 = 0
    ITEM_1 = 1
    ITEM_2 = 2
Package docs
============
   
.. toctree::

   autoapi/index

Contents:

.. toctree::
   :maxdepth: 2
templates_path = ["_templates"]
source_suffix = ".rst"
master_doc = "index"
project = "package"
copyright = "2015, readthedocs"
author = "readthedocs"
version = "0.1"
release = "0.1"
language = "en"
exclude_patterns = ["_build"]
pygments_style = "sphinx"
todo_include_todos = False
html_theme = "alabaster"
htmlhelp_basename = "Package"
extensions = ["autoapi.extension"]
autoapi_dirs = ["package"]
autoapi_file_pattern = "*.py"

The result is:

Class A Class B

Investigations πŸ”Ž

It looks like the import matters:

This fails This works This works too
from enum import IntEnum  

from .module_B import *          
from .module_B import *   

from enum import IntEnum  
from enum import IntEnum  

from .module_B import FooB

I am a bit surprised that this behavior applies even if __all__ is used in both modules.

Origin of the problem
It looks like the function resolve_qualname is the one causing the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions