← Back to index

generics_typevartuple_overloads.py

True Positive
False Positive
False Negative
Optional (detected)
Warning or Info
TP: 0
FP: 0
FN: 0
Optional: 0 / 0
1"""
2Tests the use of TypeVarTuple in function overloads.
3"""
4
5# Specification: https://typing.readthedocs.io/en/latest/spec/generics.html#overloads-for-accessing-individual-types
6
7from typing import Any, Generic, TypeVar, TypeVarTuple, assert_type, overload
8
9
10Shape = TypeVarTuple("Shape")
11Axis1 = TypeVar("Axis1")
12Axis2 = TypeVar("Axis2")
13Axis3 = TypeVar("Axis3")
16class Array(Generic[*Shape]):
17 @overload
18 def transpose(self: "Array[Axis1, Axis2]") -> "Array[Axis2, Axis1]":
19 ...
21 @overload
22 def transpose(self: "Array[Axis1, Axis2, Axis3]") -> "Array[Axis3, Axis2, Axis1]":
23 ...
25 def transpose(self) -> Any:
26 pass
29def func1(a: Array[Axis1, Axis2], b: Array[Axis1, Axis2, Axis3]):
30 assert_type(a.transpose(), Array[Axis2, Axis1])
31 assert_type(b.transpose(), Array[Axis3, Axis2, Axis1])