-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
cannot infer (or provide) types of lambdas #4226
Comments
Maybe it's because you are also using functools.partial()? IIRC mypy
doesn't yet support that very well.
|
Replacing the |
Then can you reduce the example to something smaller so there are no
distractions from the issue you're reporting? (It should be small enough
that you can easily paste it into an issue comment directly.)
|
revealed type is |
I think this is a deficiency in the "solver". Somewhere the backtracking
goes awry.
You can work around it by replacing some of the lambdas with defs.
|
See python/mypy#4226 Signed-off-by: Mike Fiedler <miketheman@gmail.com>
See python/mypy#4226 Signed-off-by: Mike Fiedler <miketheman@gmail.com>
* chore(deps): install mypy in lint.in Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): include more types-* packages for mypy These were suggested from running mypy on the codebase. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore: configure mypy Set configuration for mypy. Exclude some of the subdirectories we are not interested in testing to speed up mypy execution. Ignore any 3rd party modules that we do not have types for yet. Added links that I could find to help track completion. Does **not** set `strict` mode yet, since that's a bigger lift. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore: add mypy runner script Eventually this command should fold into `bin/lint` and be removed. For now, it's a convenient execution wrapper. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: ignore dynamic properties Callables are receiving dynamic attributes, something that isn't "usual". See python/mypy#708 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: ignore lambdas See python/mypy#4226 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: ignore hybrid_property repeat definitions Part of the SQLAlchemy extensions, which do not yet have reliable stubs/plugins. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: ignore sqlalchemy declarative Should come along with sqlalchemy stubs. See: https://docs.sqlalchemy.org/en/14/orm/extensions/mypy.html#using-declared-attr-and-declarative-mixins Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: a few more ignores Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: interface methods shouldn't use self Surfaced via mypy, corrected! Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: correct subclass path Surfaced via mypy, corrected. Unclear why this wouldn't have been caught by other tools. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: rename internal variable mypy detected this as a type mismatch, as the internal variable name was shadowing the externally-supplied one, and changing the type. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: ignore flake8 line too long for ignored types Adding a `# type: ignore` comment to a couple of places triggered flake8's line too long check. Running `make reformat` did nothing for these - black has outstanding design issues with line length and comments. See psf/black#1713 for one example. Instead of changing the line structure to accommodate, ignore these two cases, at least until the types can be fixed and the comments removed. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * Revert "chore: add mypy runner script" This reverts commit fffeadb. * test: include mypy in lint execution Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): include itsdangerous type stubs Until itsdangerous 2.0 is included, this types package is needed. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
* chore(deps): install mypy in lint.in Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): include more types-* packages for mypy These were suggested from running mypy on the codebase. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore: configure mypy Set configuration for mypy. Exclude some of the subdirectories we are not interested in testing to speed up mypy execution. Ignore any 3rd party modules that we do not have types for yet. Added links that I could find to help track completion. Does **not** set `strict` mode yet, since that's a bigger lift. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore: add mypy runner script Eventually this command should fold into `bin/lint` and be removed. For now, it's a convenient execution wrapper. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: ignore dynamic properties Callables are receiving dynamic attributes, something that isn't "usual". See python/mypy#708 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: ignore lambdas See python/mypy#4226 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: ignore hybrid_property repeat definitions Part of the SQLAlchemy extensions, which do not yet have reliable stubs/plugins. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: ignore sqlalchemy declarative Should come along with sqlalchemy stubs. See: https://docs.sqlalchemy.org/en/14/orm/extensions/mypy.html#using-declared-attr-and-declarative-mixins Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: a few more ignores Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: interface methods shouldn't use self Surfaced via mypy, corrected! Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: correct subclass path Surfaced via mypy, corrected. Unclear why this wouldn't have been caught by other tools. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: rename internal variable mypy detected this as a type mismatch, as the internal variable name was shadowing the externally-supplied one, and changing the type. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * lint: ignore flake8 line too long for ignored types Adding a `# type: ignore` comment to a couple of places triggered flake8's line too long check. Running `make reformat` did nothing for these - black has outstanding design issues with line length and comments. See psf/black#1713 for one example. Instead of changing the line structure to accommodate, ignore these two cases, at least until the types can be fixed and the comments removed. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * Revert "chore: add mypy runner script" This reverts commit fffeadb. * test: include mypy in lint execution Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): include itsdangerous type stubs Until itsdangerous 2.0 is included, this types package is needed. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
FWIW on current master mypy gives a very different output:
The current errors look much better, and it looks like they can be fixed by adding corresponding upper bounds to type variables. |
Consider this file: https://gist.github.com/bwo/077400d43c517ca0b80f2e85f615073e
The output from running mypy is:
I suspect this is related to the fact that
reveal_type(len)
andreveal_type(lambda s: len(s))
are, to my surprise, not the same (the latter acceptsAny
as input, the former requiresSized
). According to mypy docs lambdas are subject to bidirectional typechecking, but afaict sufficient information is present in the file given to type the lambdas; nevertheless, they aren't.The text was updated successfully, but these errors were encountered: