Bug Report
Class __get__ method is not working for generic specialization overload cases
To Reproduce
from __future__ importannotationsfromtypingimportSequence, Generic, TypeVar, TYPE_CHECKING, Any, overload, Mapping, Type, Optionalfromtyping_extensionsimportreveal_typeT_co=TypeVar("T_co", covariant=True)
TSequence_co=TypeVar("TSequence_co", bound=Sequence[Any], covariant=True)
classField(Generic[T_co]):
type: Optional[Type[T_co]]
ifTYPE_CHECKING:
@overloaddef__get__(self: Field[bool], instance: None, owner: Any) ->BoolField:
pass@overloaddef__get__(self: Field[int], instance: None, owner: Any) ->NumField:
pass@overloaddef__get__(self: Field[str], instance: None, owner: Any) ->StrField:
pass@overloaddef__get__(self: Field[TSequence_co], instance: None, owner: Any) ->SeqField[TSequence_co]:
pass@overloaddef__get__(self: Field[Any], instance: None, owner: Any) ->AnyField[T_co]:
pass@overloaddef__get__(self, instance: Any, owner: Any) ->T_co:
passdef__get__(self, instance: Any, owner: Any) ->Any:
passclassBoolField(Field[bool]):
passclassNumField(Field[int]):
passclassStrField(Field[str]):
passclassSeqField(Field[TSequence_co]):
passclassAnyField(Field[T_co]):
passclassFields:
bool_f: Field[bool]
cmp_f: Field[int]
str_f: Field[str]
seq_f: Field[Sequence[int]]
any_f: Field[Mapping[int, int]]
reveal_type(Fields.bool_f)
reveal_type(Fields.cmp_f)
reveal_type(Fields.str_f)
reveal_type(Fields.seq_f)
reveal_type(Fields.any_f)Expected Behavior
reveal_type show correct types based on a __get__ overloads.
pyright produce correct output:
temp.pytemp.py:71:13-information: Typeof"Fields.bool_f"is"BoolField"temp.py:72:13-information: Typeof"Fields.cmp_f"is"NumField"temp.py:73:13-information: Typeof"Fields.str_f"is"StrField"temp.py:74:13-information: Typeof"Fields.seq_f"is"SeqField[Sequence[int]]"temp.py:75:13-information: Typeof"Fields.any_f"is"AnyField[Mapping[int, int]]"0errors, 0warnings, 5informations
Actual Behavior
mypy resolves all types as BoolField:
temp.py:71:13: note: Revealedtypeis"temp.BoolField"temp.py:72:13: note: Revealedtypeis"temp.BoolField"temp.py:73:13: note: Revealedtypeis"temp.BoolField"temp.py:74:13: note: Revealedtypeis"temp.BoolField"temp.py:75:13: note: Revealedtypeis"temp.BoolField"Success: noissuesfoundin1sourcefile
Your Environment
- Mypy version used:
1.5.1 - Mypy command-line flags: -
- Mypy configuration options from
mypy.ini (and other config files): - - Python version used:
python 3.8.17
Bug Report
Class
__get__method is not working for generic specialization overload casesTo Reproduce
Expected Behavior
reveal_typeshow correct types based on a__get__overloads.pyrightproduce correct output:Actual Behavior
mypyresolves all types asBoolField:Your Environment
1.5.1mypy.ini(and other config files): -python 3.8.17