Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static-only objects are included in wildcards expansions #42

Closed
pawamoy opened this issue Feb 16, 2022 · 3 comments
Closed

Static-only objects are included in wildcards expansions #42

pawamoy opened this issue Feb 16, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@pawamoy
Copy link
Member

pawamoy commented Feb 16, 2022

Describe the bug
Currently, expanding a wildcard will include members that are only "statically" present.
More specifically: members that are defined or imported under an if TYPE_CHECKING or if False condition.
This is problematic because this can lead to cyclic aliases.

To Reproduce
Steps to reproduce the behavior:

# package/module_a.py
from typing import TYPE_CHECKING

if TYPE_CHECKING:  # always false
    from package.module_b import CONST
# package/__init__.py
from .module_a import *

At runtime, package would definitely not have CONST in its members.

Expected behavior
These "static-only" objects should not be included in wildcards expansions.

Additional context
mkdocstrings/mkdocstrings#382
Maybe an other way to fix that would be to better handle duplicate members.
But that depends on the order we add expanded wildcard's members...

@tristanlatr
Copy link

This is how I check for the TYPE checking blocks: https://github.com/tristanlatr/pydocspec/blob/main/pydocspec/astroidutils.py#L359-L374

Objects have a field is_type_guarded wich is set to True is the context is under a type guard if condition.

Then the wildcard import rely on __all__ or the public names returnde with this function: https://github.com/tristanlatr/pydocspec/blob/main/pydocspec/processor/mod_attr.py#L75-L87

@pawamoy
Copy link
Member Author

pawamoy commented Feb 20, 2022

Thanks @tristanlatr! I was indeed thinking about adding a field on objects so that we know they are type-guarded or not.

pawamoy added a commit that referenced this issue Apr 15, 2022
@pawamoy pawamoy closed this as completed Apr 15, 2022
@pawamoy
Copy link
Member Author

pawamoy commented Apr 15, 2022

Released in 0.17.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants