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

feature: Merge value when attribute is first annotated then assigned #241

Open
pawamoy opened this issue Feb 29, 2024 · 1 comment
Open
Assignees
Labels
feature New feature or request

Comments

@pawamoy
Copy link
Member

pawamoy commented Feb 29, 2024

Is your feature request related to a problem? Please describe.

In the following example:

dataclass_opts: dict[str, bool]
if sys.version_info >= (3, 10):
    dataclass_opts = {"slots": True}
else:
    dataclass_opts = {}

...the value of dataclass_opt will be None.

Describe the solution you'd like

Should we visit the if nodes instead and merge the assigned value to the previously registered annotated-only attribute?

Describe alternatives you've considered

/

Additional context

In could help value inference in #240.

@pawamoy pawamoy added the feature New feature or request label Feb 29, 2024
@pawamoy pawamoy self-assigned this Feb 29, 2024
@pawamoy
Copy link
Member Author

pawamoy commented Aug 11, 2024

If we implement this, we should first add an option to hide attribute values in mkdocstrings-python, since we've been recommending to delay assignments as a solution:

a: str  # no value shown by mkdocstrings-python
a = "hello"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant