Skip to content

Solve issues with deferral; related minor corrections#1

Closed
LordGiacomoS wants to merge 73 commits into
Viicos:union-314from
LordGiacomoS:union-314_mypy_crashfix
Closed

Solve issues with deferral; related minor corrections#1
LordGiacomoS wants to merge 73 commits into
Viicos:union-314from
LordGiacomoS:union-314_mypy_crashfix

Conversation

@LordGiacomoS

@LordGiacomoS LordGiacomoS commented Jul 14, 2026

Copy link
Copy Markdown

Fixes crash in mypy (python/mypy#21588) that caused deferral of this branch's PR (python/typeshed#13740) on the main typeshed, because while the crash could be solved in mypy, it seems more prudent to use this typeshed-based solution. Solutions that would modify mypy's code would introduce a redundant version check and still have the crash if an up-to-date version of typeshed isn't used. The exact changes that fix the crash are specifically the changes to stdlib/types.pyi in 76cf69a).

Other minor corrections:

  • get_origin overload changes (changes to stdlib/typing.pyi & stdlib/typing_extensions.pyi in 40d9f63) were done to solve conflicting overloads issue occuring during ./tests/mypy_test.py stdlib when Union changes are in effect.
    • tested to work with mypy despite changes, even in case of ParamSpecArgs or ParamSpecKwargs instances being provided.
  • changes to builtins.type.__or__ & builtins.type.__ror__ (changes to stdlib/builtins.pyi in 40d9f63) were made to fix an issue with how mypy displays reveal_type calls on pep 604 unions (e.g. reveal_type(str | int) -> types.UnionType | def () -> int).
  • remaining changes (changes to stdlib/types.pyi in 40d9f63; all changes in 96f1bf1) are minor amendments to fix incredibly minor details and make the linter happy.

Remaining Concerns:

  • Mypy still raises inaccurate concerns about Unions when running test cases (currently working on this one)
  • Pyright still raises inaccurate concerns about Unions when running test cases (next on my to-do list)
  • stubtest errors introduced by Viicos's change and still not fixed
    • typing.Union.__name__ & typing.Union.__qualname__: Given that it is valid when running mypy over code accessing these specific class properties, I don't believe this check is actually necessary, as they seemingly already exist implicitly. I'm not confident enough in this belief to touch things though.
    • unused allowlist entry notes:
      • typing.Union: It doesn't seem like classes themselves are able to be allowlist entries, so maybe this should be something like typing.Union.*?
      • others: I don't think any of these are actually necessary (or possible) to implement, unless checking for a negative, as the methods don't exist independently of typing.Union

Stubtests: https://github.com/LordGiacomoS/typeshed/actions/runs/29355015820 (runs a different branch to allow me to use modified version of mypy to fix more minor errors that aren't in scope of crash specifically)
Tests: https://github.com/LordGiacomoS/typeshed/actions/runs/28957923025

Stubtest errors excerpt

Sourced from: https://github.com/LordGiacomoS/typeshed/actions/runs/28900665825/job/85736371504

error: typing.Union.__name__ is not present in stub
Stub: in file /home/runner/work/typeshed/typeshed/stdlib/typing.pyi
MISSING
Runtime:
'Union'

error: typing.Union.__qualname__ is not present in stub
Stub: in file /home/runner/work/typeshed/typeshed/stdlib/typing.pyi
MISSING
Runtime:
'Union'

note: unused allowlist entry typing.Union
note: unused allowlist entry types.UnionType.__class_getitem__
note: unused allowlist entry types.UnionType.__mro_entries__
note: unused allowlist entry types.UnionType.__name__
note: unused allowlist entry types.UnionType.__qualname__
Found 7 errors (checked 700 modules)

Soulsuck24 and others added 30 commits June 4, 2026 13:28
Add a few additional annotations
Update subsample and zoom method signatures
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add Python 3.15 TypedDict attributes

* Use AnnotationForm for TypedDict extra items
AlexWaygood and others added 24 commits June 24, 2026 17:10
* `typing_extensions`: re-export `builtins.sentinel` on Python 3.15+

This would make ty's implementation of `builtins.sentinel` a little easier

* Update typing_extensions.pyi

* Update typing_extensions version to 4.16.0rc1

* Update typing_extensions.pyi

* allow

* a surprise, to be sure, but a welcome one

* Update stdlib/typing_extensions.pyi

* harmonize builtins and typing_extensions, fix various `__(r)or__` methods

* Apply suggestions from code review
* Update typing_extensions.TypeVarTuple with new backported features

* Update typing_extensions to 4.16.0rc2

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
…inct (python#15949)

it would be too easy for an eager contributor to revert python@4531374 in the name of simplifying the stub
* Add typed fields, queries, and update to some of the new APIs
* Type the field classes
* Type query results
* Mark kwargs TypedDicts type_check_only and fix TypedDict import
* Instead of separating get/set, just override for BigBitField.
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update most test/lint dependencies

* Update metadata.py

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
…fect

While existing examples of changing a class to an alias, such as
`shutil.ExecError` -> `RuntimeError` and `socket.timeout` -> `TimeoutError`,
use `<old> = <new>` syntax, this change causes issues for typing.Union
in particular. The syntax creates an intermediary TypeAlias object, which
is an issue in this particular case because mypy asserts that `types.UnionType`
is an actual type, and not an alias pointing to another type.

Instead, the code employs a technique regularly used by typing_extensions, and
imports the new type under the pseudonym of the old type.
Previous commit message was also amended to slightly better explain
how the crash fix actually works
- removed some inaccurate notes left over from when Viicos copied types.UnionType
- added optional `@classmethod` decorator to `typing.Union.__class_getitem__`, to be in line with `typing._Generic.__class_getitem__`
- make args of `typing.Union.__class_getitem__` positional, as per stubtest instruction
for purposes of passing certain stubtests that would otherwise fail due to outdated stubs
@LordGiacomoS

Copy link
Copy Markdown
Author

Latest commit (#2eccc22 ) fixes issue found when running test cases on python 3.14 & 3.15, across all operating systems

Issue in question

Source: https://github.com/LordGiacomoS/typeshed/actions/runs/29354539513/job/87161643214#step:4

mypy --platform {linux, darwin, win32} --python-version {3.14, 3.15} on the standard library test cases: FAILURE

stdlib/@tests/test_cases/check_types.py:82: error: Expression is of type
"<typing special form>", not "Never | Any"  [assert-type]
        assert_type(union_type | Literal[1], types.UnionType | Any)
        ^

@LordGiacomoS
LordGiacomoS marked this pull request as draft July 21, 2026 14:34
@LordGiacomoS

LordGiacomoS commented Jul 23, 2026

Copy link
Copy Markdown
Author

The changes to builtins.type.__or__ & builtins.type.__ror__ (changes to stdlib/builtins.pyi in 40d9f63) currently break mypy's handling of unions and that fact, combined with how messy this branch is (due to tacking on a number of other commits as a brute force approach to solving a specific problem) and the lack of visibility/feedback here, leads me to believe that closing this PR, cleaning up the changes, and opening one on the mainline typeshed repo is the best approach to solve these issues.

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.