File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -981,6 +981,10 @@ def expand_and_bind_callable(
981981 assert isinstance (expanded , CallableType )
982982 if var .is_settable_property and mx .is_lvalue and var .setter_type is not None :
983983 # TODO: use check_call() to infer better type, same as for __set__().
984+ if not expanded .arg_types :
985+ # This can happen when accessing invalid property from its own body,
986+ # error will be reported elsewhere.
987+ return AnyType (TypeOfAny .from_error )
984988 return expanded .arg_types [0 ]
985989 else :
986990 return expanded .ret_type
Original file line number Diff line number Diff line change @@ -8726,3 +8726,16 @@ class Fields:
87268726reveal_type(Fields.bool_f) # N: Revealed type is "__main__.BoolField"
87278727reveal_type(Fields.int_f) # N: Revealed type is "__main__.NumField"
87288728reveal_type(Fields.custom_f) # N: Revealed type is "__main__.AnyField[__main__.Custom]"
8729+
8730+ [case testRecursivePropertyWithInvalidSetterNoCrash]
8731+ class NoopPowerResource:
8732+ _hardware_type: int
8733+
8734+ @property
8735+ def hardware_type(self) -> int:
8736+ return self._hardware_type
8737+
8738+ @hardware_type.setter
8739+ def hardware_type(self) -> None: # E: Invalid property setter signature
8740+ self.hardware_type = None # Note: intentionally recursive
8741+ [builtins fixtures/property.pyi]
Original file line number Diff line number Diff line change @@ -2609,3 +2609,12 @@ class B2(B1): # E: A NamedTuple cannot be a dataclass
26092609 pass
26102610
26112611[builtins fixtures/tuple.pyi]
2612+
2613+ [case testDataclassesTypeGuard]
2614+ import dataclasses
2615+
2616+ raw_target: object
2617+
2618+ if isinstance(raw_target, type) and dataclasses.is_dataclass(raw_target):
2619+ reveal_type(raw_target) # N: Revealed type is "type[dataclasses.DataclassInstance]"
2620+ [builtins fixtures/tuple.pyi]
Original file line number Diff line number Diff line change @@ -777,3 +777,22 @@ def handle(model: Model) -> int:
777777 return process_model(model)
778778 return 0
779779[builtins fixtures/tuple.pyi]
780+
781+
782+ [case testOverloadedTypeGuardType]
783+ from __future__ import annotations
784+ from typing_extensions import TypeIs, Never, overload
785+
786+ class X: ...
787+
788+ @overload # E: An overloaded function outside a stub file must have an implementation
789+ def is_xlike(obj: Never) -> TypeIs[X | type[X]]: ... # type: ignore
790+ @overload
791+ def is_xlike(obj: type) -> TypeIs[type[X]]: ...
792+ @overload
793+ def is_xlike(obj: object) -> TypeIs[X | type[X]]: ...
794+
795+ raw_target: object
796+ if isinstance(raw_target, type) and is_xlike(raw_target):
797+ reveal_type(raw_target) # N: Revealed type is "type[__main__.X]"
798+ [builtins fixtures/tuple.pyi]
You can’t perform that action at this time.
0 commit comments