Summary
There is a difference in annotation hover and type hint display between ty and Pylance when defining a metaclass with __call__ and a class defining its own __init__ and using the metaclass.
Examlpe code:
from typing import Any, TypeVar, reveal_type
T = TypeVar("T")
class TestMeta(type):
def __call__(cls: type[T], *args: Any, **kwargs: Any) -> T: # noqa: ANN401
# expected to have more logic here...
return super().__call__(*args, **kwargs) # ty:ignore[invalid-super-argument]
class TestWithMeta(metaclass=TestMeta):
def __init__(self, val1: str, val2: int, val3: int | None = None) -> None: ...
class TestWithoutMeta:
def __init__(self, val1: str, val2: int, val3: int | None = None) -> None: ...
value1 = "val1"
value2 = 2
val_test11 = TestWithMeta(value1, value2)
# Displays TestWithMeta(...) on hover in ty
# but class TestWithMeta(
# val1: str,
# val2: int,
# val3: int | None = None
# ) in Pylance
val_test12 = TestWithoutMeta(value1, value2)
# Displays class TestWithoutMeta(
# val1: str,
# val2: int,
# val3: int | None = None
# ) in ty and Pylance
reveal_type(val_test11) # Runtime type is 'TestWithMeta'
reveal_type(val_test12) # Runtime type is 'TestWithoutMeta'
Schreenshot ty:
Schreenshot Pylance:
This Pyright issue seams to be same or similar: microsoft/pyright#5488
I also assume it may be related to the resent changes because of: #2288
Version
ty 0.0.29
Summary
There is a difference in annotation hover and type hint display between ty and Pylance when defining a metaclass with
__call__and a class defining its own__init__and using the metaclass.Examlpe code:
Schreenshot ty:
Schreenshot Pylance:
This Pyright issue seams to be same or similar: microsoft/pyright#5488
I also assume it may be related to the resent changes because of: #2288
Version
ty 0.0.29