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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

(馃悶) False positive for explicit Any with inferred Type[type] #11467

Open
KotlinIsland opened this issue Nov 5, 2021 · 9 comments
Open
Labels
bug mypy got something wrong topic-disallow-any The disallow-any-* family of flags

Comments

@KotlinIsland
Copy link
Contributor

type  # no error
t1 = type  # error: Expression type contains "Any" (has type "Type[type]")
t2: type[type] = type  # no error  
t3: Type[type] = type  # no error
@KotlinIsland KotlinIsland added the bug mypy got something wrong label Nov 5, 2021
@erictraut
Copy link

I don't see any errors when I run mypy on this code sample. I confirmed I'm running the latest published version. Can you confirm which version you're using?

@erictraut
Copy link

Thanks. I'm able to repro the problem with the "--disallow-any-expr" option enabled.

@erictraut
Copy link

This could be the intended behavior. I suspect that t1 = type is being interpreted as a type alias with an implied Any type argument.

@KotlinIsland
Copy link
Contributor Author

I think it's triggering the Any detection because:

reveal_type(type)

note: Revealed type is "Overload(def (o: builtins.object) -> builtins.type, def (name: builtins.str, bases: builtins.tuple[builtins.type], dict: builtins.dict[builtins.str, Any], **kwds: Any) -> builtins.type)"
contains Any

@KotlinIsland
Copy link
Contributor Author

but strange that it's not complaining with a bare type.

@KotlinIsland
Copy link
Contributor Author

This could be the intended behavior. I suspect that t1 = type is being interpreted as a type alias with an implied Any type argument.

This sounds more likely actually. But seems wrong to me.

@KotlinIsland
Copy link
Contributor Author

t1 = type  # error: Expression type contains "Any" (has type "Type[type]")
t2: t1[str] = str  # error: "type" expects no type arguments, but 1 given

hmmmmmmmm

@KotlinIsland
Copy link
Contributor Author

If I have --disallow-any-generics enabled and --disallow-any-expr disabled, there's no error. So I don't that's whats happening.

@KotlinIsland KotlinIsland changed the title false positive for explicit Any with inferred Type[type] (馃悶) False positive for explicit Any with inferred Type[type] Jun 22, 2022
@hauntsaninja hauntsaninja added the topic-disallow-any The disallow-any-* family of flags label Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-disallow-any The disallow-any-* family of flags
Projects
None yet
Development

No branches or pull requests

3 participants