Skip to content

Avoid widening incompatible ParamSpec constraints#21400

Open
MestreY0d4-Uninter wants to merge 2 commits intopython:masterfrom
MestreY0d4-Uninter:fix-paramspec-protocol-inference
Open

Avoid widening incompatible ParamSpec constraints#21400
MestreY0d4-Uninter wants to merge 2 commits intopython:masterfrom
MestreY0d4-Uninter:fix-paramspec-protocol-inference

Conversation

@MestreY0d4-Uninter
Copy link
Copy Markdown

Refs #21384.

Summary

This avoids widening incompatible precise ParamSpec lower-bound constraints to Any when solving constraints. In the protocol case from #21384, different protocol members can infer conflicting concrete parameter lists; joining those currently erases the conflict and lets invalid calls through.

The PR keeps imprecise ParamSpec argument constraints on the existing path, and only rejects incompatible precise Parameters constraints.

This addresses the free-function and wrapper-argument paths from the issue. The direct generic self-call form still needs separate handling.

Test Plan

  • PYTHONPATH=. uv run --no-project --isolated --with-requirements test-requirements.txt python -m pytest -q mypy/test/testcheck.py::TypeCheckSuite::check-parameter-specification.test mypy/test/testsolve.py
  • PYTHONPATH=. uv run --no-project --isolated --with-requirements test-requirements.txt python -m mypy --config-file mypy_self_check.ini mypy/solve.py
  • git diff --check

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 2, 2026

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

pwndbg (https://github.com/pwndbg/pwndbg)
+ pwndbg/commands/onegadget.py:26: error: Cannot infer function type argument  [misc]
+ pwndbg/commands/cpsr.py:18: error: Cannot infer function type argument  [misc]

antidote (https://github.com/Finistere/antidote)
+ src/antidote/core/_inject.py:293: error: Cannot infer value of type parameter "_P" of "staticmethod"  [misc]

discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/core.py:672: error: Unused "type: ignore" comment  [unused-ignore]

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.

1 participant