fluentpython / example-code-2e

Example code for Fluent Python, 2nd edition (O'Reilly 2022)
https://amzn.to/3J48u2J
MIT License
3.17k stars 902 forks source link

mysum.py - incorrect import of type Iterable from collections package #38

Closed anagri closed 10 months ago

anagri commented 1 year ago

the code incorrectly imports collections.Iterable, instead of typing.Iterable.

This error is not caught for python 3.9+ because of interpreter changes

But for python 3.8, the code throws error -

$ python mysum.py 
Traceback (most recent call last):
  File "mysum.py", line 10, in <module>
    def sum(it: Iterable[T]) -> Union[T, int]: ...  # <2>