-
-
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
Revert "Revert use of ParamSpec
for functools.wraps
"
#16942
Conversation
This is an attempt to fix e.g. python/typeshed#10653 |
This comment has been minimized.
This comment has been minimized.
Primer summary:
The next step is to go through the new errors and analyse whether they're true positives or false positives |
The ones in trio are true positives afaict @TeamSpen210 |
Yeah, that block of code's not particularly typeable, the problem is |
jinja: looks like they're already using nox: ditto, jax: looks like a true positive? bokeh: annotated function type != unannotated function type. false positive? ibis: false positive? superficially looks like |
What's next here? |
Diff from mypy_primer, showing the effect of this PR on open source code: jinja (https://github.com/pallets/jinja)
+ src/jinja2/compiler.py:56: error: Incompatible return value type (got "_Wrapped[[VarArg(Any), KwArg(Any)], Any, [VarArg(Any), KwArg(Any)], Any]", expected "F") [return-value]
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/utilities/asyncutils.py:222: error: Argument 1 to "wraps" has incompatible type "T"; expected "Callable[..., object]" [arg-type]
+ src/prefect/utilities/asyncutils.py:222: error: Argument 1 to "wraps" has incompatible type "T"; expected "Callable[[VarArg(Never), KwArg(Never)], Never]" [arg-type]
+ src/prefect/utilities/asyncutils.py:264: error: Need type annotation for "wrapper" [var-annotated]
- src/prefect/utilities/asyncutils.py:270: error: "Callable[[VarArg(Any), KwArg(Any)], Any]" has no attribute "aio" [attr-defined]
+ src/prefect/utilities/asyncutils.py:270: error: "_Wrapped[Any, Any, [VarArg(Any), KwArg(Any)], Any]" has no attribute "aio" [attr-defined]
- src/prefect/utilities/asyncutils.py:271: error: Incompatible return value type (got "Callable[[VarArg(Any), KwArg(Any)], Any]", expected "T") [return-value]
+ src/prefect/utilities/asyncutils.py:271: error: Incompatible return value type (got "_Wrapped[Any, Any, [VarArg(Any), KwArg(Any)], Any]", expected "T") [return-value]
tornado (https://github.com/tornadoweb/tornado)
+ tornado/gen.py:268: error: Unused "type: ignore" comment [unused-ignore]
nox (https://github.com/wntrblm/nox)
+ nox/_decorators.py:54: error: Incompatible types in assignment (expression has type "_Wrapped[[VarArg(Any), KwArg(Any)], Any, [VarArg(Any), KwArg(Any)], Any]", variable has type "FunctionType") [assignment]
trio (https://github.com/python-trio/trio)
+ src/trio/_core/_ki.py:142: error: Type of decorated function contains type "Any" ("_Wrapped[ArgsT, CoroutineType[Any, Any, Any], ArgsT, RetT]") [misc]
+ src/trio/_core/_ki.py:152: error: Type of decorated function contains type "Any" ("_Wrapped[ArgsT, GeneratorType[Any, Any, Any], ArgsT, RetT]") [misc]
+ src/trio/_core/_ki.py:168: error: Argument 1 to "wraps" has incompatible type "Union[Callable[ArgsT, AsyncGeneratorType[Any, Any]], Callable[..., AsyncGeneratorType[object, object]]]"; expected "Callable[[VarArg(object), KwArg(object)], AsyncGeneratorType[Any, Any]]" [arg-type]
+ src/trio/_core/_ki.py:169: error: Type of decorated function contains type "Any" ("_Wrapped[object, AsyncGeneratorType[Any, Any], ArgsT, RetT]") [misc]
jax (https://github.com/google/jax)
+ jax/_src/maps.py:627: error: Incompatible return value type (got "_Wrapped[[VarArg(Any), KwArg(Any)], Any, [VarArg(Any), KwArg(Any)], Any]", expected "Wrapped") [return-value]
+ jax/_src/maps.py:627: note: "_Wrapped" is missing following "Wrapped" protocol member:
+ jax/_src/maps.py:627: note: lower
bokeh (https://github.com/bokeh/bokeh)
+ src/bokeh/document/callbacks.py: note: In member "add_session_callback" of class "DocumentCallbackManager":
+ src/bokeh/document/callbacks.py:185:31: error: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "_Wrapped[[], None, [], None]") [assignment]
ibis (https://github.com/ibis-project/ibis)
+ ibis/expr/types/relations.py:3037: error: Missing positional argument "predicates" in call to "__call__" of "_Wrapped" [call-arg]
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/wrapper/_implementations.py:503: error: Incompatible types in assignment (expression has type "Zen[P, R]", variable has type "Callable[[Any], Any]") [assignment]
+ src/hydra_zen/wrapper/_implementations.py:503: error: Incompatible types in assignment (expression has type "Zen[P, R]", variable has type "_Wrapped[P, R, [Any], Any]") [assignment]
- src/hydra_zen/wrapper/_implementations.py:503: note: "Zen[P, R].__call__" has type "Callable[[DataClass_ | type[DataClass_] | dict[Any, Any] | DictConfig | str], R]"
|
The bokeh hit looks unavoidable, the variable is assigned different types in two branches and mypy generally doesn't like that. I suspect the ibis hit is because mypy thinks we have an unbound method wrapping a bound one (https://github.com/ibis-project/ibis/blob/7667328ada9cb8ef6bb4c456636c6a7ccab2ad1a/ibis/expr/types/joins.py#L274). Probably hard to avoid, but I'm also not sure why ibis needs the Overall, this feels like it's probably an improvement. |
What do I need to do to get this landed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the impact seems overall positive, and even if it was neutral, it's still better to stay closer to typeshed. Let's merge this.
This is an experiment to see if we can remove
mypy/misc/sync-typeshed.py
Line 185 in 790e8a7
mypy/misc/generate_changelog.py
Line 82 in 790e8a7
/cc @AlexWaygood