The reason will be displayed to describe this comment to others. Learn more.
Added a bunch of tests for subtyping (btw this uncovered one type combination I missed). Also added few basic things for joins. All works as expected.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
All reactions
reveal_type(A()) # N: Revealed type is "__main__.Foo"
reveal_type(A().foo()) # N: Revealed type is "builtins.str"
[case testNewReturnType14]
from __future__ import annotations
class A:
def __new__(cls) -> int: raise # E: Incompatible return type for "__new__" (returns "int", but must return a subtype of "A")
class B(A):
@classmethod
def foo(cls) -> int: raise
reveal_type(B.foo()) # N: Revealed type is "builtins.int"
[builtins fixtures/classmethod.pyi]
[case testNewReturnType15]
from typing import Generic, Type, TypeVar
T = TypeVar("T")
class A(Generic[T]):
def __new__(cls) -> B[int]: ...
@classmethod
def foo(cls: Type[A[T]]) -> T: ...
class B(A[T]): ...
# The Never without error is not ideal, but matches the behavior without custom __new__().
reveal_type(B.foo()) # N: Revealed type is "Never"
reveal_type(B[str].foo()) # N: Revealed type is "builtins.str"
class C(A[str]): ...
reveal_type(C.foo()) # N: Revealed type is "builtins.str"
[builtins fixtures/classmethod.pyi]
[case testNewReturnType16]
from typing import Generic, TypeVar
T = TypeVar("T")
class A(Generic[T]):
def __new__(cls, *args, **kwargs) -> T: # E: "__new__" must return a class instance (got "T")
...
class Model:
pass
reveal_type(A[Model]()) # N: Revealed type is "__main__.Model"
class B(A[Model]):
pass
reveal_type(B()) # N: Revealed type is "__main__.Model"
[builtins fixtures/dict.pyi]
[case testNewReturnType17]
class C:
def __new__(self) -> D:
return D()
class D(C):
x: int
C.x # E: "type[C]" has no attribute "x"
[case testMetaclassPlaceholderNode]
from sympy.assumptions import ManagedProperties
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.