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 error for list of two callables #13182

Open
KotlinIsland opened this issue Jul 19, 2022 · 8 comments
Open

(馃悶) False positive error for list of two callables #13182

KotlinIsland opened this issue Jul 19, 2022 · 8 comments
Labels
bug mypy got something wrong

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Jul 19, 2022

This list is perfectly valid. only usages should be an error.

def f1(*, a: int): ...
def f2(*, b: int): ...

[f1, f2]  # error: List item 0 has incompatible type "(NamedArg(int, 'a')) -> None]"; expected "(NamedArg(int, 'b')) -> None"

playground

@KotlinIsland KotlinIsland added the bug mypy got something wrong label Jul 19, 2022
@ethanhs
Copy link
Collaborator

ethanhs commented Jul 21, 2022

First of all, unions are unordered, and defining some metric for sorting names can become a lot more complex as the names get more complicated.

Secondly, mypy is correct to give an error in your second example (which I'm not sure if it is related to the issue here of ordering names) as the following code:

a = [f1, f2]

for fn in a:
    fn(a = 4)

would error.

@KotlinIsland
Copy link
Contributor Author

@ethanhs It's not that the error shouldn't be there, it's that the error is complaining about the first element in the list.

I fixed this issue locally and that case is now reporting correctly, so I think they are related.

@erictraut
Copy link

The expression [f1, f2] is valid and doesn't violate any type consistency rules, so an error should not be emitted here. The statement fn(a = 4) in the follow-on example is a type violation and should result in an error, but the original expression [f1, f2] is valid. So this does appear to be a bug in mypy.

@JelleZijlstra JelleZijlstra changed the title (馃悶) A join between a union and an instance will be in the wrong order False positive error for list of two callables Jul 23, 2022
@JelleZijlstra
Copy link
Member

Updated the issue title to reflect the actual bug.

@KotlinIsland KotlinIsland changed the title False positive error for list of two callables (馃悶) False positive error for list of two callables Jul 23, 2022
@KotlinIsland
Copy link
Contributor Author

@JelleZijlstra Do you think the original issue is valid? Should I re raise it

@JelleZijlstra
Copy link
Member

Yes it's valid. We can use this issue to track it.

@KotlinIsland
Copy link
Contributor Author

They seem like completely different issues

@erictraut
Copy link

Your original post included two issues. The first was about unions, and that was already answered. Unions are not ordered, so that's not a bug. The second issue is a legitimate bug, and the title of this issue was changed to reflect that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

4 participants