Код: Выделить всё
from collections import deque
from typing import Iterable
import numpy as np
def mean[T](a: Iterable[T]) -> T:
s = sum(a)
return s * (1.0/len(a))
c = mean([1.0, 1.5])
print(c)
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = mean([a, b])
print(c)
print(mean((1,2,3)) )
d = deque([a,b])
print(mean(d))
mypy mypy_explore.py
Код: Выделить всё
mypy_explore.py:8: error: Argument 1 to "sum" has incompatible type "Iterable[T]"; expected "Iterable[bool]" [arg-type]
mypy_explore.py:9: error: Unsupported operand types for / ("float" and "int") [operator]
mypy_explore.py:9: error: Argument 1 to "len" has incompatible type "Iterable[T]"; expected "Sized" [arg-type]
mypy_explore.py:17: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[Any]]", variable has type "float") [assignment]
Found 4 errors in 1 file (checked 1 source file)
Подробнее здесь: https://stackoverflow.com/questions/792 ... s-and-mypy
Мобильная версия