Open thorwhalen opened 3 years ago
from typing import TypeVar, Iterable T = TypeVar('T') ClosedAggregator = Callable[[Iterable[T]], T] def representative(s: Iterable[T], aggr: ClosedAggregator) -> Iterable[T]: a = aggr(s) return (x / a for x in s) def first(s): return s[0] representative([1,2,3], first) def not_an_aggr(s): return s[:4] representative([1,2,3], not_an_aggr) # !!! No linting happens! ???
But will happen if I explicitly tell it that the function doesn't return T
T
def not_an_aggr(s) -> Iterable[T]: return s[:4] representative([1,2,3], not_an_aggr) # linting happens
Interestingly enough, it doesn't complain with -> int, but does complain with list (but whose to say that T is not a list?)
-> int
list
But will happen if I explicitly tell it that the function doesn't return
T
Interestingly enough, it doesn't complain with
-> int
, but does complain withlist
(but whose to say thatT
is not a list?)