Skip to content

[ty] Support type[None] in type expressions#22892

Merged
AlexWaygood merged 1 commit intomainfrom
alex/type-t-none
Jan 27, 2026
Merged

[ty] Support type[None] in type expressions#22892
AlexWaygood merged 1 commit intomainfrom
alex/type-t-none

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Jan 27, 2026

Summary

This is mandated by the typing conformance suite.

I'm honestly quite sceptical that it should be mandated by the conformance suite, but that's a battle for another day. It's trivial to support it now, and it'll be trivial to rip it out and emit an error instead at a later date if the spec is amended. Anything is better than that status quo (which is a @Todo type).

Test Plan

mdtests

@AlexWaygood AlexWaygood requested a review from carljm as a code owner January 27, 2026 16:50
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Jan 27, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 27, 2026

Typing conformance results improved 🎉

The percentage of diagnostics emitted that were expected errors increased from 79.08% to 79.11%. The percentage of expected errors that received a diagnostic increased from 70.44% to 70.53%.

Summary

Metric Old New Diff Outcome
True Positives 760 761 +1 ⏫ (✅)
False Positives 201 201 +0
False Negatives 319 318 -1 ⏬ (✅)
Total Diagnostics 961 962 +1
Precision 79.08% 79.11% +0.02% ⏫ (✅)
Recall 70.44% 70.53% +0.09% ⏫ (✅)

True positives added

Details
Location Name Message
specialtypes_none.py:41:7 invalid-argument-type Argument to function func2 is incorrect: Expected <class 'NoneType'>, found None

@AlexWaygood AlexWaygood marked this pull request as draft January 27, 2026 16:54
@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 27, 2026

mypy_primer results

Changes were detected when running on open source projects
strawberry (https://github.com/strawberry-graphql/strawberry)
- strawberry/experimental/pydantic/error_type.py:106:70: error[invalid-assignment] Object of type `list[tuple[str, Any, Field[Unknown]] | tuple[Any, @Todo | type[list[Unknown]], dataclasses.Field[None]]]` is not assignable to `list[tuple[str, Any, Field[Unknown]]]`
+ strawberry/experimental/pydantic/error_type.py:106:70: error[invalid-assignment] Object of type `list[tuple[str, Any, Field[Unknown]] | tuple[Any, <class 'NoneType'> | type[list[Unknown]] | Any, dataclasses.Field[None]]]` is not assignable to `list[tuple[str, Any, Field[Unknown]]]`

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 14489 diagnostics
+ Found 14488 diagnostics

No memory usage changes detected ✅

@AlexWaygood AlexWaygood changed the title [ty] Ban type[None] in type expressions [ty] Support type[None] in type expressions Jan 27, 2026
@AlexWaygood AlexWaygood marked this pull request as ready for review January 27, 2026 17:04
@AlexWaygood
Copy link
Member Author

I misread what the conformance suite was asking of us here initially -- and I'm not sure the demands it's making are really correct in this case. But I think there's no harm in supporting this for now.

@AlexWaygood AlexWaygood merged commit e5019b3 into main Jan 27, 2026
49 checks passed
@AlexWaygood AlexWaygood deleted the alex/type-t-none branch January 27, 2026 17:28
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