Skip to content

Fix inference when Any is passed as a type object - #21865

Open
yhuikzdtguioaert wants to merge 1 commit into
python:masterfrom
yhuikzdtguioaert:fix-20859-infer-any-type-object
Open

Fix inference when Any is passed as a type object#21865
yhuikzdtguioaert wants to merge 1 commit into
python:masterfrom
yhuikzdtguioaert:fix-20859-infer-any-type-object

Conversation

@yhuikzdtguioaert

@yhuikzdtguioaert yhuikzdtguioaert commented Aug 17, 2026

Copy link
Copy Markdown

Fixes #20859.

Recent typeshed versions represent typing.Any as a class at runtime. When that value was passed to a parameter of type type[T], constraint inference extracted its internal typing.Any instance literally instead of treating it as the dynamic Any type. This produced a type that displayed as Any but was not semantically Any, so assert_type(foo(Any), Any) reported the confusing Any versus Any error.

This normalizes the typing.Any instance while inferring constraints from type objects. Other class objects keep their existing instance type. The regression test uses a class-based typing.Any fixture and checks both assert_type and the revealed inferred type.

Validation:

  • Regression test: 1 passed
  • check-classes.test: 610 passed, 1 xfailed
  • mypy self-check: 196 source files clean
  • pre-commit lint suite: passed
  • Full pytest run: 13,907 passed, 653 skipped, 11 xfailed; 33 unrelated mypyc runtime tests failed because the Windows linker could not create the generated librt .exp file (LNK1104).

@yhuikzdtguioaert
yhuikzdtguioaert force-pushed the fix-20859-infer-any-type-object branch from 15ff590 to 0e2d95f Compare August 17, 2026 22:03
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

error: Expression is of type "Any", not "Any" (Using Any as a type)

1 participant