Skip to content

Handle edge case in overload subtyping - #22007

Merged
ilevkivskyi merged 2 commits into
python:masterfrom
ilevkivskyi:overload-subtype
Sep 20, 2026
Merged

ilevkivskyi merged 2 commits into
python:masterfrom
ilevkivskyi:overload-subtype

Conversation

@ilevkivskyi

@ilevkivskyi ilevkivskyi commented Sep 19, 2026

Copy link
Copy Markdown
Member

Fixes #495
Fixes #12379

The solution is straightforward: we already have an existing (decent) method to union similar callables, so I simply refactor the code so that it can be used in subtypes.py to handle the relevant edge case.

cc @JukkaL @hauntsaninja

@github-actions

This comment has been minimized.

@ilevkivskyi

Copy link
Copy Markdown
Member Author

Oh, it looks like using make_simplified_union() here causes an infinite recursion. I will take a look.

@ilevkivskyi

Copy link
Copy Markdown
Member Author

The actual problem was a reckless freshen_function_type_vars() call (such things don't play well with protocol subtype checks, as we will create a technically new type in each recursion, because of a different TypeVarId).

@github-actions

Copy link
Copy Markdown
Contributor

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

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/helpers.py:990: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_response.py:500: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_response.py:509: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_request.py:327: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_request.py:336: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_app.py:147: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_app.py:162: error: Unused "type: ignore" comment  [unused-ignore]

scikit-learn (https://github.com/scikit-learn/scikit-learn)
+ sklearn/externals/array_api_extra/testing/_testing.py:389: error: Unused "type: ignore" comment  [unused-ignore]

pywin32 (https://github.com/mhammond/pywin32)
+ win32/Lib/win32timezone.py:673: error: Unused "type: ignore" comment  [unused-ignore]
+ win32/Lib/win32timezone.py:728: error: Unused "type: ignore" comment  [unused-ignore]
+ win32/Lib/win32timezone.py:739: error: Unused "type: ignore" comment  [unused-ignore]

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/series.py:791: error: Unused "type: ignore" comment  [unused-ignore]
+ static_frame/core/series.py:4075: error: Unused "type: ignore" comment  [unused-ignore]
+ static_frame/core/bus.py:680: error: Unused "type: ignore" comment  [unused-ignore]

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, old issue fix!

@ilevkivskyi
ilevkivskyi merged commit ed82143 into python:master Sep 20, 2026
25 checks passed
@ilevkivskyi
ilevkivskyi deleted the overload-subtype branch September 20, 2026 16: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.

Incompatible override when overriding non-overload with overload Overloaded function as a subtype of function with union types args/return

2 participants