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

RUF012 does not respect type aliases #16174

Open
marcuslimdw opened this issue Feb 15, 2025 · 3 comments · May be fixed by #16210
Open

RUF012 does not respect type aliases #16174

marcuslimdw opened this issue Feb 15, 2025 · 3 comments · May be fixed by #16210
Assignees
Labels
bug Something isn't working type-inference Requires more advanced type inference.

Comments

@marcuslimdw
Copy link

Description

On 0.9.6, the following snippet triggers RUF012:

from collections.abc import Mapping
from typing import TypeAlias

Values: TypeAlias = Mapping[str, str]


class Base:
    values: Values


class Derived(Base):
    values: Values = {"a": "b"}  # RUF012 

However, if values: Values is replaced with values: Mapping[str, str], the error goes away.

Using the Python 3.12 type statement instead of TypeAlias does not change the behaviour.

@ntBre
Copy link
Contributor

ntBre commented Feb 15, 2025

Thanks for the report! I think we could probably try to resolve the type alias here, at least within the same file.

The general case requires type inference as mentioned in some related issues like #13137, #13630, #5639, and #5429.

@ntBre ntBre added bug Something isn't working type-inference Requires more advanced type inference. labels Feb 15, 2025
@vladNed
Copy link
Contributor

vladNed commented Feb 17, 2025

I can work on this if its fine with you guys.

@MichaReiser
Copy link
Member

Sure, go for it

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

Successfully merging a pull request may close this issue.

4 participants