GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Respect explicit return type of __new__() by ilevkivskyi · Pull Request #21441 · python/mypy

Respect explicit return type of __new__() #21441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
ilevkivskyi merged 18 commits into python:master from ilevkivskyi:new-new
May 27, 2026
+627 −111
Merged

Respect explicit return type of __new__() #21441

Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b5ea90c
Preparatory refactor
ilevkivskyi May 5, 2026
a43ecc1
Add basic logic
ilevkivskyi May 6, 2026
c930a95
Add boilerplate
ilevkivskyi May 7, 2026
8c3e017
Do not use ret_type in various special cases
ilevkivskyi May 7, 2026
b01ffea
Store precise type
ilevkivskyi May 8, 2026
b76c746
Some more tweaks
ilevkivskyi May 8, 2026
73bb465
Update docstring
ilevkivskyi May 8, 2026
4434f73
Fix one more casual ret_type
ilevkivskyi May 8, 2026
b921130
Do not leak type variables in type[T]
ilevkivskyi May 8, 2026
e356348
Merge remote-tracking branch 'upstream/master' into new-new
ilevkivskyi May 11, 2026
7916bf1
Try alternative implementation of exceptions
ilevkivskyi May 11, 2026
daba172
Fix weird stuff
ilevkivskyi May 11, 2026
f8c159b
Merge remote-tracking branch 'upstream/master' into new-new
ilevkivskyi May 22, 2026
97791b4
Address CR
ilevkivskyi May 23, 2026
4519e3f
Skip TypeVars completely; inline the call
ilevkivskyi May 23, 2026
65869e1
Merge remote-tracking branch 'upstream/master' into new-new
ilevkivskyi May 26, 2026
97534e4
Add tests; fix inference
ilevkivskyi May 26, 2026
107ede7
Some more tests
ilevkivskyi May 27, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Some more tests
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@ilevkivskyi
ilevkivskyi committed May 27, 2026
commit 107ede7c65d907a68ba36ab2b6a3cac09e169186

Some comments aren't visible on the classic Files Changed page.

There are no files selected for viewing

37 changes: 37 additions & 0 deletions 37 test-data/unit/check-classes.test
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7677,10 +7677,13 @@ class A:

T = TypeVar("T")
def foo(f: Callable[[], T]) -> T: ...
def bar(t: type[T]) -> T: ...

ta: type[A]
reveal_type(foo(A)) # N: Revealed type is "builtins.int"
reveal_type(foo(ta)) # N: Revealed type is "builtins.int"
reveal_type(bar(A)) # N: Revealed type is "__main__.A"
reveal_type(bar(ta)) # N: Revealed type is "__main__.A"

[case testNewReturnTypeCallableNarrowing]
from typing import Callable, TypeVar
Expand All @@ -7700,6 +7703,40 @@ if issubclass(tx, B):
reveal_type(tx) # N: Revealed type is "type[__main__.B]"
[builtins fixtures/isinstancelist.pyi]

[case testNewReturnTypeOverloadNarrowing]
from typing import TypeVar, Generic, Union, overload

T = TypeVar("T", int, str)

class Series(Generic[T]):
@overload
def __new__(cls, dtype: int) -> IntSeries: ...
@overload
def __new__(cls, dtype: type[T]) -> Series[T]: ...
@overload
def __new__(cls, dtype=...) -> Series: ...
def __new__(cls, dtype=...) -> Series:
...

class IntSeries(Series[int]): ...

class Index:
@overload
def __new__(cls, dtype: int) -> IntIndex: ...
@overload
def __new__(cls, dtype=...) -> Index: ...
def __new__(cls, dtype=...) -> Index:
...

class IntIndex(Index): ...

def foo(x: Union[Series, int, Index]):
if isinstance(x, (Series, Index)):
reveal_type(x) # N: Revealed type is "__main__.Series[Any] | __main__.Index"
else:
reveal_type(x) # N: Revealed type is "builtins.int"
[builtins fixtures/isinstancelist.pyi]

[case testMetaclassPlaceholderNode]
from sympy.assumptions import ManagedProperties
from sympy.ops import AssocOp
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.