Skip to content

[ty] Reduce false positives when subscripting classes generic over TypeVarTuples#22950

Merged
AlexWaygood merged 1 commit intomainfrom
alex/fewer-646-false-positives
Jan 29, 2026
Merged

[ty] Reduce false positives when subscripting classes generic over TypeVarTuples#22950
AlexWaygood merged 1 commit intomainfrom
alex/fewer-646-false-positives

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Jan 29, 2026

Summary

We don't support TypeVarTuple yet, but it's fairly easy to reduce the number of TypeVarTuple-related false positives we have in the mean time.

Test Plan

mdtests

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

astral-sh-bot bot commented Jan 29, 2026

Typing conformance results

The percentage of diagnostics emitted that were expected errors increased from 80.00% to 81.22%. The percentage of expected errors that received a diagnostic decreased from 71.42% to 71.23%.

Summary

Metric Old New Diff Outcome
True Positives 772 770 -2 ⏬ (❌)
False Positives 193 178 -15 ⏬ (✅)
False Negatives 309 311 +2 ⏫ (❌)
Total Diagnostics 965 948 -17
Precision 80.00% 81.22% +1.22% ⏫ (✅)
Recall 71.42% 71.23% -0.19% ⏬ (❌)

False positives removed

Details
Location Name Message
generics_typevartuple_specialization.py:102:20 not-subscriptable Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
generics_typevartuple_specialization.py:103:21 not-subscriptable Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
generics_typevartuple_specialization.py:130:14 not-subscriptable Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
generics_typevartuple_specialization.py:134:14
generics_typevartuple_specialization.py:134:33
generics_typevartuple_specialization.py:134:59
not-subscriptable
not-subscriptable
not-subscriptable
Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
generics_typevartuple_specialization.py:143:14 not-subscriptable Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
generics_typevartuple_specialization.py:147:15
generics_typevartuple_specialization.py:147:41
not-subscriptable
not-subscriptable
Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
generics_typevartuple_specialization.py:153:8 not-subscriptable Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
generics_typevartuple_specialization.py:156:24
generics_typevartuple_specialization.py:156:55
not-subscriptable
not-subscriptable
Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
generics_typevartuple_specialization.py:92:14
generics_typevartuple_specialization.py:92:42
not-subscriptable
not-subscriptable
Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized

True positives removed

Details
Location Name Message
generics_typevartuple_specialization.py:127:5 not-subscriptable Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized
generics_typevartuple_specialization.py:163:8 not-subscriptable Cannot subscript non-generic type: <class 'tuple[@Todo(PEP 646), ...]'> is already specialized

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 29, 2026

mypy_primer results

Changes were detected when running on open source projects
prefect (https://github.com/PrefectHQ/prefect)
+ src/integrations/prefect-dbt/prefect_dbt/core/settings.py:94:28: error[invalid-assignment] Object of type `dict[Any, Any] | int | dict[str, Any] | ... omitted 4 union elements` is not assignable to `dict[str, Any]`
+ src/integrations/prefect-dbt/prefect_dbt/core/settings.py:99:28: error[invalid-assignment] Object of type `int | dict[Any, Any] | float | ... omitted 3 union elements` is not assignable to `dict[str, Any]`
+ src/prefect/cli/deploy/_core.py:86:21: error[invalid-assignment] Object of type `dict[Any, Any] | int | dict[str, Any] | ... omitted 4 union elements` is not assignable to `dict[str, Any]`
+ src/prefect/cli/deploy/_core.py:87:21: error[invalid-assignment] Object of type `int | dict[Any, Any] | float | ... omitted 3 union elements` is not assignable to `dict[str, Any]`
+ src/prefect/deployments/steps/core.py:137:38: error[invalid-argument-type] Argument is incorrect: Argument type `dict[Any, Any] | int | dict[str, Any] | ... omitted 4 union elements` does not satisfy constraints (`str`, `int`, `int | float`, `bool`, `dict[Any, Any]`, `list[Any]`, `None`) of type variable `T`
- src/prefect/utilities/templating.py:320:13: error[invalid-assignment] Invalid subscript assignment with key of type `object` and value of type `Unknown | dict[str, Any]` on object of type `dict[str, Any]`
+ src/prefect/utilities/templating.py:320:13: error[invalid-assignment] Invalid subscript assignment with key of type `object` and value of type `Unknown | int | dict[str, Any] | ... omitted 4 union elements` on object of type `dict[str, Any]`
- src/prefect/utilities/templating.py:323:16: error[invalid-return-type] Return type does not match returned value: expected `T@resolve_block_document_references | dict[str, Any]`, found `list[Unknown | dict[str, Any]]`
+ src/prefect/utilities/templating.py:323:16: error[invalid-return-type] Return type does not match returned value: expected `T@resolve_block_document_references | dict[str, Any]`, found `list[Unknown | int | dict[str, Any] | ... omitted 4 union elements]`
- src/prefect/utilities/templating.py:437:16: error[invalid-return-type] Return type does not match returned value: expected `T@resolve_variables`, found `dict[object, Unknown]`
+ src/prefect/utilities/templating.py:437:16: error[invalid-return-type] Return type does not match returned value: expected `T@resolve_variables`, found `dict[object, Unknown | int | float | ... omitted 4 union elements]`
- src/prefect/utilities/templating.py:442:16: error[invalid-return-type] Return type does not match returned value: expected `T@resolve_variables`, found `list[Unknown]`
+ src/prefect/utilities/templating.py:442:16: error[invalid-return-type] Return type does not match returned value: expected `T@resolve_variables`, found `list[Unknown | int | float | ... omitted 4 union elements]`
- src/prefect/workers/base.py:232:13: error[invalid-argument-type] Argument is incorrect: Argument type `str | dict[str, Any]` does not satisfy constraints (`str`, `int`, `int | float`, `bool`, `dict[Any, Any]`, `list[Any]`, `None`) of type variable `T`
+ src/prefect/workers/base.py:232:13: error[invalid-argument-type] Argument is incorrect: Argument type `str | int | dict[str, Any] | ... omitted 3 union elements` does not satisfy constraints (`str`, `int`, `int | float`, `bool`, `dict[Any, Any]`, `list[Any]`, `None`) of type variable `T`
+ src/prefect/workers/base.py:234:20: error[invalid-argument-type] Argument expression after ** must be a mapping type: Found `int | Unknown | float | ... omitted 4 union elements`
- Found 5368 diagnostics
+ Found 5374 diagnostics

core (https://github.com/home-assistant/core)
- homeassistant/util/variance.py:47:12: error[invalid-return-type] Return type does not match returned value: expected `(**_P@ignore_variance) -> _R@ignore_variance`, found `_Wrapped[_P@ignore_variance, int | _R@ignore_variance | float | datetime, _P@ignore_variance, _R@ignore_variance | int | float | datetime]`
- Found 14515 diagnostics
+ Found 14514 diagnostics

No memory usage changes detected ✅

@AlexWaygood AlexWaygood force-pushed the alex/fewer-646-false-positives branch 2 times, most recently from 56af9bd to ca3ea46 Compare January 29, 2026 18:45
@AlexWaygood
Copy link
Member Author

The two "true positives removed" here were not errors that were being emitted for the right reason or with the right error messages, so I think this is a good tradeoff.

@AlexWaygood AlexWaygood marked this pull request as ready for review January 29, 2026 18:49
@AlexWaygood AlexWaygood merged commit 5a479da into main Jan 29, 2026
49 checks passed
@AlexWaygood AlexWaygood deleted the alex/fewer-646-false-positives branch January 29, 2026 22:28
carljm added a commit that referenced this pull request Jan 30, 2026
* main: (76 commits)
  [ty] Improve the check for `NewType`s with generic bases (#22961)
  [ty] Ban legacy `TypeVar` bounds or constraints from containing type variables (#22949)
  Bump the typing conformance suite pin (#22960)
  [ty] Emit an error if a TypeVarTuple is used to subscript `Generic` or `Protocol` without being unpacked (#22952)
  [ty] Reduce false positives when subscripting classes generic over `TypeVarTuple`s (#22950)
  [ty] Detect invalid attempts to subclass `Protocol[]` and `Generic[]` simultaneously (#22948)
  Fix suppression indentation matching (#22903)
  Remove hidden `--output-format` warning (#22944)
  [ty] Validate signatures of dataclass `__post_init__` methods (#22730)
  [ty] extend special-cased `numbers` diagnostic to `invalid-argument-type` errors (#22938)
  [ty] Avoid false positive for `not-iterable` with no-positive intersection types (#22089)
  [ty] Preserve pure negation types in descriptor protocol (#22907)
  [ty] add special-case diagnostic for `numbers` module (#22931)
  [ty] Move the location of more `invalid-overload` diagnostics (#22933)
  [ty] Fix unary and comparison operators for TypeVars with union bounds (#22925)
  [ty] Rule Selection: ignore/warn/select all rules (unless subsequently overriden) (#22832)
  [ty] Fix TypedDict construction from existing TypedDict values (#22904)
  [ty] fix bug in string annotations and clean up diagnostics (#22913)
  [ty] Improve support for goto-type, goto-declaration, hover, and highlighting of string annotations (#22878)
  [ty] Rename old typing imports to new on `unresolved-reference`. (#22827)
  ...
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.

2 participants

Comments