Skip to content

Conversation

@cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Aug 31, 2025

Source commit:
python/typeshed@2480d7e

cdce8p and others added 8 commits September 1, 2025 01:03
This is allegedly causing large performance problems, see 13821

typeshed/8231 had zero hits on mypy_primer, so it's not the worst thing
to undo. Patching this in typeshed also feels weird, since there's a
more general soundness issue. If a typevar has a bound or constraint, we
might not want to solve it to a Literal.

If we can confirm the performance regression or fix the unsoundness
within mypy, I might pursue upstreaming this in typeshed.

(Reminder: add this to the sync_typeshed script once merged)
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

beartype (https://github.com/beartype/beartype)
+ beartype/_util/hint/pep/proposal/pep484/pep484generic.py:149: error: Unused "type: ignore" comment  [unused-ignore]
+ beartype/_util/hint/pep/proposal/pep484/pep484generic.py:177: error: Unused "type: ignore" comment  [unused-ignore]

spack (https://github.com/spack/spack)
+ lib/spack/spack/util/url.py:91: error: Cannot assign to final name "uses_netloc"  [misc]
+ lib/spack/spack/util/url.py:92: error: Cannot assign to final name "uses_relative"  [misc]
+ lib/spack/spack/util/url.py:95: error: Cannot assign to final name "uses_netloc"  [misc]
+ lib/spack/spack/util/url.py:96: error: Cannot assign to final name "uses_relative"  [misc]

pydantic (https://github.com/pydantic/pydantic)
- pydantic/main.py:577: error: Argument 2 to "issubclass" has incompatible type "<typing special form>"; expected "_ClassInfo"  [arg-type]
- pydantic/dataclasses.py:203: error: Argument 2 to "issubclass" has incompatible type "<typing special form>"; expected "_ClassInfo"  [arg-type]
- pydantic/dataclasses.py:205: error: Incompatible types in assignment (expression has type "tuple[type[DataclassInstance], <typing special form>]", variable has type "tuple[type[DataclassInstance]]")  [assignment]
+ pydantic/dataclasses.py:205: error: Incompatible types in assignment (expression has type "tuple[type[DataclassInstance], Any]", variable has type "tuple[type[DataclassInstance]]")  [assignment]

psycopg (https://github.com/psycopg/psycopg)
+ tests/types/test_uuid.py:62: error: Unused "type: ignore" comment  [unused-ignore]

prefect (https://github.com/PrefectHQ/prefect)
- ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:136: note: "__init_subclass__" of "object" defined here
+ ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:138: note: "__init_subclass__" of "object" defined here
- ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:136: note: "__init_subclass__" of "object" defined here
+ ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:138: note: "__init_subclass__" of "object" defined here
- ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:136: note: "__init_subclass__" of "object" defined here
+ ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:138: note: "__init_subclass__" of "object" defined here
- ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:136: note: "__init_subclass__" of "object" defined here
+ ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:138: note: "__init_subclass__" of "object" defined here
- ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:136: note: "__init_subclass__" of "object" defined here
+ ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:138: note: "__init_subclass__" of "object" defined here

core (https://github.com/home-assistant/core)
+ homeassistant/components/backup/manager.py:900: error: Subclass of "dict[str, Exception]" and "BackupNotFound" cannot exist: have distinct disjoint bases  [unreachable]
+ homeassistant/components/bayesian/binary_sensor.py:558: error: Subclass of "Template" and "str" cannot exist: have distinct disjoint bases  [unreachable]
+ homeassistant/components/bayesian/binary_sensor.py:559: error: Statement is unreachable  [unreachable]

zulip (https://github.com/zulip/zulip)
- ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:114: note: "SubTest" defined here
+ ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:116: note: "SubTest" defined here

strawberry (https://github.com/strawberry-graphql/strawberry)
+ strawberry/utils/typing.py:135: error: Unused "type: ignore" comment  [unused-ignore]
+ strawberry/utils/typing.py:185: error: Unused "type: ignore" comment  [unused-ignore]
- ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:136: note: "__init_subclass__" of "object" defined here
+ ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:138: note: "__init_subclass__" of "object" defined here

pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/raises.py:455: error: Subclass of "GenericAlias" and "Exception" cannot exist: have distinct disjoint bases  [unreachable]
+ src/_pytest/raises.py:468: error: Subclass of "GenericAlias" and "type" cannot exist: have distinct disjoint bases  [unreachable]
+ src/_pytest/raises.py:470: error: Subclass of "GenericAlias" and "BaseException" cannot exist: have distinct disjoint bases  [unreachable]

pandas (https://github.com/pandas-dev/pandas)
- pandas/io/common.py:1050: note:     def __init__(self, file: str | PathLike[str] | _ZipWritable, mode: Literal['w', 'x'] = ..., compression: int = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, strict_timestamps: bool = ..., metadata_encoding: None = ...) -> ZipFile
+ pandas/io/common.py:1050: note:     def __init__(self, file: str | PathLike[str] | _ZipWritable, mode: Literal['w', 'x'], compression: int = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, strict_timestamps: bool = ..., metadata_encoding: None = ...) -> ZipFile
- pandas/io/common.py:1050: note:     def __init__(self, file: str | PathLike[str] | _ZipReadableTellable, mode: Literal['a'] = ..., compression: int = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, strict_timestamps: bool = ..., metadata_encoding: None = ...) -> ZipFile
+ pandas/io/common.py:1050: note:     def __init__(self, file: str | PathLike[str] | _ZipReadableTellable, mode: Literal['a'], compression: int = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, strict_timestamps: bool = ..., metadata_encoding: None = ...) -> ZipFile
- pandas/_testing/_io.py:141: note:     def __init__(self, file: str | PathLike[str] | _ZipWritable, mode: Literal['w', 'x'] = ..., compression: int = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, strict_timestamps: bool = ..., metadata_encoding: None = ...) -> ZipFile
+ pandas/_testing/_io.py:141: note:     def __init__(self, file: str | PathLike[str] | _ZipWritable, mode: Literal['w', 'x'], compression: int = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, strict_timestamps: bool = ..., metadata_encoding: None = ...) -> ZipFile
- pandas/_testing/_io.py:141: note:     def __init__(self, file: str | PathLike[str] | _ZipReadableTellable, mode: Literal['a'] = ..., compression: int = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, strict_timestamps: bool = ..., metadata_encoding: None = ...) -> ZipFile
+ pandas/_testing/_io.py:141: note:     def __init__(self, file: str | PathLike[str] | _ZipReadableTellable, mode: Literal['a'], compression: int = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, strict_timestamps: bool = ..., metadata_encoding: None = ...) -> ZipFile

aioredis (https://github.com/aio-libs/aioredis)
+ aioredis/client.py:4116: error: Unused "type: ignore" comment  [unused-ignore]
+ aioredis/client.py:4152: error: Unused "type: ignore" comment  [unused-ignore]

discord.py (https://github.com/Rapptz/discord.py)
- ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/typing.pyi:1016: note: "update" of "TypedDict" defined here
+ ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/typing.pyi:1043: note: "update" of "TypedDict" defined here
- discord/ext/commands/converter.py:1280: error: Argument 2 to "issubclass" has incompatible type "<typing special form>"; expected "_ClassInfo"  [arg-type]

ibis (https://github.com/ibis-project/ibis)
- ibis/common/collections.py:140: error: Argument 1 to "KeysView" has incompatible type "ibis.common.collections.Mapping[K, V]"; expected "typing.Mapping[K, Any]"  [arg-type]
- ibis/common/collections.py:143: error: Argument 1 to "ItemsView" has incompatible type "ibis.common.collections.Mapping[K, V]"; expected "typing.Mapping[K, V]"  [arg-type]
+ ibis/common/collections.py:282: error: Class "FrozenDict" has incompatible disjoint bases  [misc]
- ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:114: note: "Any" defined here
+ ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:116: note: "Any" defined here
+ ibis/common/tests/test_patterns.py:273: error: Class "MyString" has incompatible disjoint bases  [misc]
+ ibis/common/tests/test_patterns.py:288: error: Class "MyInt" has incompatible disjoint bases  [misc]
+ ibis/common/tests/test_patterns.py:486: error: Class "MyList" has incompatible disjoint bases  [misc]
+ ibis/common/tests/test_patterns.py:1141: error: Class "MyFloat" has incompatible disjoint bases  [misc]
+ ibis/common/tests/test_patterns.py:1211: error: Class "DoubledList" has incompatible disjoint bases  [misc]
+ ibis/common/tests/test_patterns.py:1238: error: Class "MyNegativeInt" has incompatible disjoint bases  [misc]
+ ibis/common/tests/test_grounds.py:184: error: Class "Integer" has incompatible disjoint bases  [misc]
+ ibis/common/tests/test_grounds.py:190: error: Class "Float" has incompatible disjoint bases  [misc]
+ ibis/common/tests/test_grounds.py:202: error: Class "MyInt" has incompatible disjoint bases  [misc]
+ ibis/common/tests/test_grounds.py:208: error: Class "MyFloat" has incompatible disjoint bases  [misc]
- ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:114: note: "__init__" of "object" defined here
+ ...venv/lib/python3.13/site-packages/mypy/typeshed/stdlib/builtins.pyi:116: note: "__init__" of "object" defined here

zope.interface (https://github.com/zopefoundation/zope.interface)
- src/zope/interface/common/collections.py:233: error: Incompatible types in assignment (expression has type "type[ItemsView[_KT_co, _VT_co]]", base class "ISet" defined the type as "type[AbstractSet[_T_co]]")  [assignment]
+ src/zope/interface/common/collections.py:233: error: Incompatible types in assignment (expression has type "type[ItemsView[_KT_co, _VT_co]]", base class "IMappingView" defined the type as "type[MappingView]")  [assignment]
- src/zope/interface/common/collections.py:237: error: Incompatible types in assignment (expression has type "type[KeysView[_KT_co]]", base class "ISet" defined the type as "type[AbstractSet[_T_co]]")  [assignment]
+ src/zope/interface/common/collections.py:237: error: Incompatible types in assignment (expression has type "type[KeysView[_KT_co]]", base class "IMappingView" defined the type as "type[MappingView]")  [assignment]
+ src/zope/interface/common/collections.py:241: error: Incompatible types in assignment (expression has type "type[ValuesView[_VT_co]]", base class "IMappingView" defined the type as "type[MappingView]")  [assignment]

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/series_mapping.py:21: error: Unused "type: ignore" comment  [unused-ignore]
+ static_frame/core/series_mapping.py:26: error: Unused "type: ignore" comment  [unused-ignore]
+ static_frame/core/series_mapping.py:32: error: Unused "type: ignore" comment  [unused-ignore]

@cdce8p
Copy link
Collaborator Author

cdce8p commented Aug 31, 2025

Mypy primer hits

@cdce8p cdce8p requested a review from hauntsaninja August 31, 2025 23:55
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Aug 31, 2025

Not necessarily merge blocking, but the ibis core pytest changes related to PEP 800 are a little worrisome to me, let's look

the ibis ones just seem like false positives
first hit in core seems like a true positive, but the second one about BackupNotFound doesn't make sense to me
pytest one is a false positive but we can live with it since typing something as types.GenericAlias is confusing

@cdce8p
Copy link
Collaborator Author

cdce8p commented Sep 1, 2025

first hit in core seems like a true positive, but the second one about BackupNotFound doesn't make sense to me

I did look at the Home Assistant errors in more detail. They are both correct. The one you mentioned is actually missing another loop. Will open a PR for it upstream tomorrow.

         agent_errors = {
             backup_id: error
             for backup_id, error_dict in zip(backup_ids, delete_results, strict=True)
+            for error in error_dict.values()
             if error and not isinstance(error, BackupNotFound)
         }

--

Not necessarily merge blocking, but the ibis core pytest changes related to PEP 800 are a little worrisome to me

As far as I see it there are two options (for this PR): either we keep it as is or I can add a patch to revert the PEP 800 changes from typeshed. If possible I'd like to move forward with it soon though so it can still be included in 1.18.

Personally I wouldn't mind testing it with the PEP 800 changes for now. If we discover those cause to many disruptions, we can always add a patch later.

@hauntsaninja
Copy link
Collaborator

Yeah, I'm happy to merge!

@hauntsaninja hauntsaninja merged commit b1b8b0c into python:master Sep 1, 2025
20 checks passed
@cdce8p cdce8p deleted the sync-typeshed branch September 1, 2025 06:56
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.

3 participants