You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand that Mypy tends to be conservative with its type inferences. However, I'm unclear as to why it doesn't utilize the information from the type variables to infer the type as Signal[builtins.tuple[str, int]] (a fixed-length tuple) like Pyright does.
Instead, it infers it as Signal[builtins.tuple[_T_co1, ...]] (a variadic tuple). Why does it prefer this generalization?
from __future__ import annotations
from typing import TypeVar, Generic, reveal_type
T1_signal = TypeVar('T1_signal')
class Signal(Generic[T1_signal]):
def __init__(self: Signal[T1_signal], __t1: type[T1_signal]) -> None:
return
test = Signal(tuple[str, int])
reveal_type(test)
# mypy: Signal[builtins.tuple[_T_co1, ...]]
# pyright: Signal[builtins.tuple[str, int]]
Thanks for the response. Isn't this related to #9003 and the more general #9773 (so called new special form TypeForm[T])?
I had this in the back of my mind, but I didn't think Pyright was addressing this specific use case, instead of returning whatever the definition of tuple in builtins.pyi is (which is what I assume is happening with mypy here).
I understand that Mypy tends to be conservative with its type inferences. However, I'm unclear as to why it doesn't utilize the information from the type variables to infer the type as
Signal[builtins.tuple[str, int]]
(a fixed-length tuple) like Pyright does.Instead, it infers it as
Signal[builtins.tuple[_T_co1, ...]]
(a variadic tuple). Why does it prefer this generalization?https://mypy-play.net/?mypy=latest&python=3.11&flags=new-type-inference%2Cstrict&gist=5ee508bb32ae745f6a4e41415d345c2b
https://pyright-playground.decorator-factory.su/?gzip=H4sIAK65J2UC_02PMQuDQAyF9_yKbCrYwVVo125dKl1EjsPm5ODMyV0s-O97iooZAkm-PN4zwY-olJllDqQU2nHyQVAze9FiPUcwKyLLZHk4zs0y0UeHEp_EFGxfYqAfaacSRgBNpaIdWDu8H2iencusAIDe6RjxvS3yXaU9ka6oATDVl0xyZ9mKUnkkZ-r958KWiZCqXi3SVQJvD3x5pnpTWitQSsnbeGlCUZLR3YvMk6M2SgpnWboCLsnyFS3gD1XOPu80AQAA
Expected Behavior
A more direct inference when it sees a fixed-tuple as a type argument, without generalizing for the variadic nature of tuple.
Your Environment
The text was updated successfully, but these errors were encountered: