Skip to content

Commit dbb42ab

Browse files
committed
chore(typing): More isinstance_or_issubclass overloads
- Related (#2717) While I was looking for unreachable code, I noticed some `isinstance_or_issubclass` cases were marked as unreachable. They *are* reachable, but when I wrote (#1997) we only had up to a **3**-tuple. The current max of **7** wasn't covered, so this PR fixes that
1 parent 7e37f03 commit dbb42ab

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

narwhals/_utils.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
_T1 = TypeVar("_T1")
106106
_T2 = TypeVar("_T2")
107107
_T3 = TypeVar("_T3")
108+
_T4 = TypeVar("_T4")
109+
_T5 = TypeVar("_T5")
110+
_T6 = TypeVar("_T6")
111+
_T7 = TypeVar("_T7")
108112
_Fn = TypeVar("_Fn", bound="Callable[..., Any]")
109113
P = ParamSpec("P")
110114
R = TypeVar("R")
@@ -718,6 +722,76 @@ def isinstance_or_issubclass(
718722
) -> TypeIs[_T1 | _T2 | _T3 | type[_T1 | _T2 | _T3]]: ...
719723

720724

725+
@overload
726+
def isinstance_or_issubclass(
727+
obj_or_cls: type, cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4]]
728+
) -> TypeIs[type[_T1 | _T2 | _T3 | _T4]]: ...
729+
730+
731+
@overload
732+
def isinstance_or_issubclass(
733+
obj_or_cls: object | type,
734+
cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4]],
735+
) -> TypeIs[_T1 | _T2 | _T3 | _T4 | type[_T1 | _T2 | _T3 | _T4]]: ...
736+
737+
738+
@overload
739+
def isinstance_or_issubclass(
740+
obj_or_cls: type,
741+
cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5]],
742+
) -> TypeIs[type[_T1 | _T2 | _T3 | _T4 | _T5]]: ...
743+
744+
745+
@overload
746+
def isinstance_or_issubclass(
747+
obj_or_cls: object | type,
748+
cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5]],
749+
) -> TypeIs[_T1 | _T2 | _T3 | _T4 | _T5 | type[_T1 | _T2 | _T3 | _T4 | _T5]]: ...
750+
751+
752+
@overload
753+
def isinstance_or_issubclass(
754+
obj_or_cls: type,
755+
cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5], type[_T6]],
756+
) -> TypeIs[type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6]]: ...
757+
758+
759+
@overload
760+
def isinstance_or_issubclass(
761+
obj_or_cls: object | type,
762+
cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5], type[_T6]],
763+
) -> TypeIs[
764+
_T1 | _T2 | _T3 | _T4 | _T5 | _T6 | type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6]
765+
]: ...
766+
767+
768+
@overload
769+
def isinstance_or_issubclass(
770+
obj_or_cls: type,
771+
cls_or_tuple: tuple[
772+
type[_T1], type[_T2], type[_T3], type[_T4], type[_T5], type[_T6], type[_T7]
773+
],
774+
) -> TypeIs[type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6 | _T7]]: ...
775+
776+
777+
@overload
778+
def isinstance_or_issubclass(
779+
obj_or_cls: object | type,
780+
cls_or_tuple: tuple[
781+
type[_T1], type[_T2], type[_T3], type[_T4], type[_T5], type[_T6], type[_T7]
782+
],
783+
) -> TypeIs[
784+
_T1
785+
| _T2
786+
| _T3
787+
| _T4
788+
| _T5
789+
| _T6
790+
| _T7
791+
| type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6 | _T7]
792+
]: ...
793+
794+
721795
@overload
722796
def isinstance_or_issubclass(
723797
obj_or_cls: Any, cls_or_tuple: tuple[type, ...]

0 commit comments

Comments
 (0)