kachayev / fn.py

Functional programming in Python: implementation of missing features to enjoy FP
Other
3.35k stars 204 forks source link

fix: import failure on Python >=3.10 #92

Open lucasew opened 2 years ago

lucasew commented 2 years ago

My worry is that this breaks backward compatibility because the typing module was added on Python 3.5 [1], so it would only work on Python 3.5 and above.

We realized this because the nixpkgs CI [2] fails to package this library to be used by other dependents. It's not that a huge problem because basically all of the stuff depends on the version based on Python 3.9, that works fine [3].

[1] https://docs.python.org/3/library/typing.html

[2] https://hydra.nixos.org/job/nixpkgs/trunk/python310Packages.fn.x86_64-linux

[3] https://hydra.nixos.org/job/nixpkgs/trunk/python39Packages.fn.x86_64-linux

Closes https://github.com/kachayev/fn.py/issues/91 https://github.com/kachayev/fn.py/issues/86

ftsfranklin commented 1 year ago

Duplicate of #87, which has better compatibility.

typing.Iterable is just a generic fork of collections.abc.Iterable, and was deprecated in 3.9.

This one should work for newer Python versions, while not breaking compatibility with older ones:

try:
    from collections.abc import Iterable
except ImportError:  # py < 3.3
    from collections import Iterable