Skip to content

[ty] Add a diagnostic if a TypeVar is used to specialize a ParamSpec, or vice versa#23738

Merged
AlexWaygood merged 1 commit intomainfrom
alex/paramspec-specializing-tvar
Mar 5, 2026
Merged

[ty] Add a diagnostic if a TypeVar is used to specialize a ParamSpec, or vice versa#23738
AlexWaygood merged 1 commit intomainfrom
alex/paramspec-specializing-tvar

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Mar 5, 2026

Summary

Add validation to detect this error:

def f[**P](x: list[P]): ...

We already emitted an error for the reverse, i.e.

from typing import Callable

class Foo[**P, T]:
    x: Callable[P, T]

def f[T](x: Foo[T, T]): ...

but we didn't have any tests for it -- I added some.

Test Plan

mdtests and snapshots

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Mar 5, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 5, 2026

Typing conformance results improved 🎉

The percentage of diagnostics emitted that were expected errors increased from 85.73% to 85.74%. The percentage of expected errors that received a diagnostic increased from 78.45% to 78.54%.

Summary

Metric Old New Diff Outcome
True Positives 859 860 +1 ⏫ (✅)
False Positives 143 143 +0
False Negatives 236 235 -1 ⏬ (✅)
Total Diagnostics 1002 1003 +1
Precision 85.73% 85.74% +0.01% ⏫ (✅)
Recall 78.45% 78.54% +0.09% ⏫ (✅)

True positives added

Details
Location Name Message
generics_paramspec_basic.py:31:19 invalid-type-arguments ParamSpec P cannot be used to specialize type variable _T

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 5, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 5, 2026

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
+ src/scikit_build_core/build/wheel.py:99:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 57 diagnostics
+ Found 58 diagnostics

@AlexWaygood AlexWaygood force-pushed the alex/paramspec-specializing-tvar branch 2 times, most recently from 76f8425 to a8af417 Compare March 5, 2026 14:03
@AlexWaygood AlexWaygood force-pushed the alex/paramspec-specializing-tvar branch from a8af417 to f463905 Compare March 5, 2026 14:04
@AlexWaygood AlexWaygood marked this pull request as ready for review March 5, 2026 14:13
@AlexWaygood AlexWaygood merged commit db77d7b into main Mar 5, 2026
51 checks passed
@AlexWaygood AlexWaygood deleted the alex/paramspec-specializing-tvar branch March 5, 2026 14:51
carljm added a commit that referenced this pull request Mar 5, 2026
* main:
  Update conformance suite commit hash (#23746)
  conformance.py: Collapse the summary paragraph when nothing changed (#23745)
  [ty] Make inferred specializations line up with source types more better (#23715)
  Bump 0.15.5 (#23743)
  [ty] Render all changed diagnostics in conformance.py (#23613)
  [ty] Split deferred checks out of `types/infer/builder.rs` (#23740)
  Discover markdown files by default in preview mode (#23434)
  [ty] Use `HasOptionalDefinition` for `except` handlers (#23739)
  [ty] Fix precedence of `all` selector in TOML configurations (#23723)
  [ty] Make `all` selector case sensitive (#23713)
  [ty] Add a diagnostic if a `TypeVar` is used to specialize a `ParamSpec`, or vice versa (#23738)
  [ty] Override home directory in ty tests (#23724)
  [ty] More type-variable default validation (#23639)
  [ty] Validate bare ParamSpec usage in type annotations, and support stringified ParamSpecs as the first argument to `Callable` (#23625)
  [ty] Add `all` selector to ty.json's `schema` (#23721)
  [ty] Add quotes to related issues links (#23720)
  [ty] Fix panic on incomplete except handlers (#23708)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants