Skip to content

Experiment: Can we use ParamSpec in functools.wraps yet?#11

Closed
AlexWaygood wants to merge 3 commits intomasterfrom
paramspec-experiment
Closed

Experiment: Can we use ParamSpec in functools.wraps yet?#11
AlexWaygood wants to merge 3 commits intomasterfrom
paramspec-experiment

Conversation

@AlexWaygood
Copy link
Copy Markdown
Owner

@AlexWaygood AlexWaygood commented Sep 16, 2023

No description provided.

@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Copy Markdown

Linking this back to the discussion at python@7d987a1#commitcomment-127920750 for reference (since it's hard to find comments on commits)

@AlexWaygood AlexWaygood changed the title Paramspec experiment Experiment: Can we use ParamSpec in functools.wraps yet? Sep 26, 2023
ilevkivskyi added a commit to python/mypy that referenced this pull request Sep 27, 2023
…16178)

This should help with re-enabling the use of `ParamSpec` in
`functools.wraps` (as it looks like some of the new errors in
AlexWaygood#11 are caused by not handling
this).

---------

Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
@AlexWaygood AlexWaygood restored the paramspec-experiment branch September 28, 2023 06:14
@AlexWaygood AlexWaygood reopened this Sep 28, 2023
@github-actions
Copy link
Copy Markdown

Diff from mypy_primer, showing the effect of this PR on open source code:

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/utilities/asyncutils.py:218: error: Argument 1 to "wraps" has incompatible type "T"; expected "Callable[..., object]"  [arg-type]
+ src/prefect/utilities/asyncutils.py:218: error: Argument 1 to "wraps" has incompatible type "T"; expected "Callable[[VarArg(Never), KwArg(Never)], Never]"  [arg-type]
+ src/prefect/utilities/asyncutils.py:260: error: Need type annotation for "wrapper"  [var-annotated]
- src/prefect/utilities/asyncutils.py:266: error: "Callable[[VarArg(Any), KwArg(Any)], Any]" has no attribute "aio"  [attr-defined]
+ src/prefect/utilities/asyncutils.py:266: error: "_Wrapped[Any, Any, [VarArg(Any), KwArg(Any)], Any]" has no attribute "aio"  [attr-defined]
- src/prefect/utilities/asyncutils.py:267: error: Incompatible return value type (got "Callable[[VarArg(Any), KwArg(Any)], Any]", expected "T")  [return-value]
+ src/prefect/utilities/asyncutils.py:267: error: Incompatible return value type (got "_Wrapped[Any, Any, [VarArg(Any), KwArg(Any)], Any]", expected "T")  [return-value]

jax (https://github.com/google/jax)
+ jax/_src/maps.py:626: 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:626: note: "_Wrapped" is missing following "Wrapped" protocol member:
+ jax/_src/maps.py:626: note:     lower

ibis (https://github.com/ibis-project/ibis)
- ibis/expr/deferred.py:317: error: Incompatible return value type (got "Callable[[VarArg(Any), KwArg(Any)], Any]", expected "F")  [return-value]
+ ibis/expr/deferred.py:317: error: Incompatible return value type (got "_Wrapped[[VarArg(Any), KwArg(Any)], Any, [VarArg(Any), KwArg(Any)], Any]", expected "F")  [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]

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]

mitmproxy (https://github.com/mitmproxy/mitmproxy): typechecking got 1.44x slower (37.2s -> 53.6s)
(Performance measurements are based on a single noisy sample)

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]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/wrapper/_implementations.py:456: error: Incompatible types in assignment (expression has type "Zen[P, R]", variable has type "Callable[[Any], Any]")  [assignment]
+ src/hydra_zen/wrapper/_implementations.py:456: 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:456: note: "Zen[P, R].__call__" has type "Callable[[DataClass_ | type[DataClass_] | dict[Any, Any] | DictConfig | str], R]"

@AlexWaygood
Copy link
Copy Markdown
Owner Author

AlexWaygood commented Sep 28, 2023

Looks like python@d25d680 cut two errors off the diff @ilevkivskyi. But tbh, I'm still not sure what using ParamSpec here gets us, and it's still causing new errors in four projects

@AlexWaygood
Copy link
Copy Markdown
Owner Author

We now use ParamSpec for functools.wraps in mypy 🎉

@AlexWaygood AlexWaygood deleted the paramspec-experiment branch March 25, 2024 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants