3 ms·
Well yes, but # optionally: Number = Union[int, float, complex] def sum_and_stringify(nums: Iterable[Number]) -> str: return str(sum(nums)) al
by zardeh 10y ago
Well yes, but
# optionally: Number = Union[int, float, complex]
def sum_and_stringify(nums: Iterable[Number]) -> str:
return str(sum(nums))
also works. Except no one knows what the Number abstract base class is (or even the Iterable abstract base class for that matter)
- clusmore 10y agoYeah but as I said it can still go far more general than just int, float and complex. It could be any arbitrary class defined by somebody else that I could not possibly know about at design time, and so a whitelisting approach of concrete classes is simply not going to cut it. It would be nice to have a way to describe the actual requirements (only that the elements support __add__ and __radd__).
- zardeh 10y agoWell, my joke was that numbers.Number exists, and I think supports those operations, but even someone complaining about this topic is unaware that it exists.