Some functions like numpy.intersect1d return differents types (in this case an ndarray or a tuple of three ndarrays) but the compiler can only infer one of them, so if I like to make:
intersection: np.ndarray = np.intersect1d([1, 2, 3], [5, 6, 2])
It throws a type warning:
Expected type 'ndarray', got 'Tuple[ndarray, ndarray, ndarray]' instead
I could avoid this kind of problems in other languages like Typescript where I could use the as
keyword to assert the type (without impact in runtime). I've read the documentation and saw the cast function, but I'd to know if there is any inline solution or something I'm missing.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…