-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
groupby with generic key function fails #9920
Comments
I edited the issue with a |
I suspect this is a bug in mypy's constraint solver. It works fine in pyright. I'll note that in the above example, the use of the TypeVar |
Yup, this is maybe my least favourite mypy issue. Thanks for the report, closing as a duplicate of the issues you mentioned. Lambda's are somewhat special cased in mypy's inference logic, so not sure there's an easy way to translate that to a fix. I think #5738 is the issue that has the most constructive discussion on this subject. |
@hauntsaninja: Is it worth keeping this open as an important / motivating use case, as per #6697 (comment) ? |
I think it's covered / since the other issues are mentioned Github will link. It just needs to be fixed :-( |
Bug Report
Passing a generic function as
key
togroupby
fails to type-check.To Reproduce
This is the motivating example I encountered:
Mypy returns the following error:
I could simplify it down to the following:
Error:
In both cases, it works if the
key
function is modified to be non-generic.Your Environment
Workaround
In both cases, wrapping the generic function application in a
lambda
+ application seems make the code type-check correctly:This might be helpful for a fix, if Mypy can implicitly do whatever the above ends up doing?
The text was updated successfully, but these errors were encountered: