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 — Believe more __new__ return types by hauntsaninja · Pull Request #16020 · python/mypy

Believe more __new__ return types #16020

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

Closed
hauntsaninja wants to merge 8 commits into python:master from hauntsaninja:abide-by-new

Uh oh!

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

Closed

Believe more __new__ return types #16020

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit Hold shift + click to select a range
4616fa2
Believe arbitrary __new__ return types
hauntsaninja Sep 2, 2023
e2d3a5e
changes
hauntsaninja Sep 2, 2023
2bd91d5
more changes
hauntsaninja Sep 2, 2023
393b303
hacks
hauntsaninja Sep 4, 2023
7b7d76d
fix instantiate
hauntsaninja Sep 4, 2023
aa5df74
clarify comment
hauntsaninja Sep 4, 2023
59a5aee
clarify comment
hauntsaninja Sep 5, 2023
cdccffa
Merge branch 'master' into abide-by-new
JelleZijlstra Jul 5, 2024
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
Next Next commit
Believe arbitrary __new__ return types
Fixes #1020 (comment)
Surprisingly popular comment on a closed issue.

We still issue the warning, but we do trust the return type instead of
overruling it.

Maybe fixes #16012
  • Loading branch information

Uh oh!

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

@hauntsaninja
hauntsaninja committed Sep 2, 2023
commit 4616fa23246d28f435d1abb269670702ebf755b9

There are no files selected for viewing

4 changes: 2 additions & 2 deletions 4 mypy/typeops.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ def class_callable(
# by accident. Like `Hashable` is a subtype of `object`. See #11799
and isinstance(default_ret_type, Instance)
and not default_ret_type.type.is_protocol
# Only use the declared return type from __new__ or declared self in __init__
# Only use the declared return type from declared self in __init__
# if it is actually returning a subtype of what we would return otherwise.
and is_subtype(explicit_type, default_ret_type, ignore_type_params=True)
and (is_new or is_subtype(explicit_type, default_ret_type, ignore_type_params=True))
):
ret_type: Type = explicit_type
else:
Expand Down
4 changes: 2 additions & 2 deletions 4 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 @@ -6883,7 +6883,7 @@ class A:
def __new__(cls) -> int: # E: Incompatible return type for "__new__" (returns "int", but must return a subtype of "A")
pass

reveal_type(A()) # N: Revealed type is "__main__.A"
reveal_type(A()) # N: Revealed type is "builtins.int"

[case testNewReturnType4]
from typing import TypeVar, Type
Expand Down Expand Up @@ -6960,7 +6960,7 @@ class A:
class B(A):
pass

reveal_type(B()) # N: Revealed type is "__main__.B"
reveal_type(B()) # N: Revealed type is "__main__.A"

[case testNewReturnType10]
# https://github.com/python/mypy/issues/11398
Expand Down
2 changes: 1 addition & 1 deletion 2 test-data/unit/check-enum.test
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ class Bar(Foo):
A = 1
B = 2

a = Bar.A
a = Bar.A # E: "Type[Foo]" has no attribute "A"
reveal_type(a.value) # N: Revealed type is "Any"
reveal_type(a._value_) # N: Revealed type is "Any"
[builtins fixtures/primitives.pyi]
Expand Down
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.