fix ParamSpec forwarding doesn't work #823#2678
fix ParamSpec forwarding doesn't work #823#2678asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
Conversation
|
Diff from mypy_primer, showing the effect of this PR on open source code: pytest-robotframework (https://github.com/detachhead/pytest-robotframework)
- ERROR pytest_robotframework/__init__.py:303:30-68: Expected `P` to be a ParamSpec value in function `_KeywordDecorator.inner` [bad-argument-type]
zulip (https://github.com/zulip/zulip)
- ERROR zerver/lib/profile.py:34:30-53: Expected `ParamT` to be a ParamSpec value in function `cProfile.Profile.runcall` [bad-argument-type]
prefect (https://github.com/PrefectHQ/prefect)
- ERROR src/prefect/_internal/concurrency/api.py:32:23-46: Expected `P` to be a ParamSpec value in function `prefect._internal.concurrency.calls.Call.new` [bad-argument-type]
- ERROR src/prefect/utilities/asyncutils.py:400:44-73: Expected `P` to be a ParamSpec value in function `run_async_from_worker_thread` [bad-argument-type]
- ERROR src/prefect/utilities/asyncutils.py:404:37-66: Expected `P` to be a ParamSpec value in function `run_async_in_new_loop` [bad-argument-type]
paasta (https://github.com/yelp/paasta)
- ERROR paasta_tools/async_utils.py:184:24-51: Expected `P` to be a ParamSpec value in function `run_sync` [bad-argument-type]
async-utils (https://github.com/mikeshardmind/async-utils)
- ERROR src/async_utils/gen_transform.py:182:36-56: Expected `P` to be a ParamSpec value in function `_sync_to_async_gen` [bad-argument-type]
- ERROR src/async_utils/gen_transform.py:219:35-55: Expected `P` to be a ParamSpec value in function `_sync_to_async_gen` [bad-argument-type]
starlette (https://github.com/encode/starlette)
- ERROR starlette/applications.py:101:50-85: Expected `P` to be a ParamSpec value in function `starlette.middleware.Middleware.__init__` [bad-argument-type]
- ERROR starlette/background.py:31:30-53: Expected `P` to be a ParamSpec value in function `BackgroundTask.__init__` [bad-argument-type]
scrapy (https://github.com/scrapy/scrapy)
- ERROR scrapy/utils/asyncio.py:222:34-57: Expected `_P` to be a ParamSpec value in function `AsyncioLoopingCall.__init__` [bad-argument-type]
- ERROR scrapy/utils/defer.py:288:60-290:6: Expected `_P` to be a ParamSpec value in function `_AsyncCooperatorAdapter.__init__` [bad-argument-type]
- ERROR scrapy/utils/defer.py:430:31-54: Expected `_P` to be a ParamSpec value in function `_maybeDeferred_coro` [bad-argument-type]
|
Primer Diff Classification✅ 7 improvement(s) | 7 project(s) total 7 improvement(s) across pytest-robotframework, zulip, prefect, paasta, async-utils, starlette, scrapy.
Detailed analysis✅ Improvement (7)pytest-robotframework (-1)
zulip (-1)
prefect (-3)
The PR description confirms this was a bug fix: 'deferred ParamSpec resolution now recognizes the case where the solver has bound the callee's ParamSpec to a quantified P, and it reuses the existing
paasta (-1)
async-utils (-2)
starlette (-2)
scrapy (-3)
In each case, the ParamSpec
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (7 LLM) |
There was a problem hiding this comment.
Pull request overview
Fixes ParamSpec forwarding between generic helper functions by improving deferred ParamSpec resolution when the callee’s ParamSpec is already bound to a quantified ParamSpec, avoiding incorrect forcing into a concrete ParamList and eliminating the erroneous “Expected P to be a ParamSpec value” diagnostic.
Changes:
- Updates callable argument matching to recognize quantified ParamSpecs and validate forwarding via existing
*P.args / **P.kwargschecks. - Adjusts argument iteration to support inspecting the “remaining args” tail when a ParamSpec is encountered.
- Adds a regression test covering forwarding between two generic helpers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyrefly/lib/alt/callable.rs |
Extends ParamSpec handling to support quantified ParamSpec forwarding and routes validation through the P.args/P.kwargs path. |
pyrefly/lib/test/paramspec.rs |
Adds a regression testcase for forwarding Callable[P, R] with *args: P.args, **kwargs: P.kwargs between helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Summary
Fixes #823
deferred ParamSpec resolution now recognizes the case where the solver has bound the callee’s ParamSpec to a quantified P, and it reuses the existing
*P.args / **P.kwargsvalidation path instead of incorrectly forcing P into a concrete ParamList.removes the bogus Expected 'P' to be a ParamSpec value error when one generic helper forwards another helper’s
Callable[P, R], *args: P.args, **kwargs: P.kwargs.Test Plan
added a regression test