adding sentinel metaclass example

This commit is contained in:
Luciano Ramalho
2021-05-23 22:12:13 -03:00
parent 8a330d822b
commit f248baf418
14 changed files with 220 additions and 1 deletions

13
15-more-types/mysum.py Normal file
View File

@@ -0,0 +1,13 @@
from functools import reduce # <1>
from operator import add
from typing import overload, Iterable, Union, TypeVar
T = TypeVar('T')
S = TypeVar('S') # <2>
@overload
def sum(it: Iterable[T]) -> Union[T, int]: ... # <3>
@overload
def sum(it: Iterable[T], /, start: S) -> Union[T, S]: ... # <4>
def sum(it, /, start=0): # <5>
return reduce(add, it, start)