kyan001/ping3

4.0.6 fails to import in Python <3.10

Closed this issue ยท 6 comments

The most recent version (4.0.6) triggered by commit aa9998d fails to import in Python 3.9.13:

Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ping3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\VirtEnvs\ping3\lib\site-packages\ping3\__init__.py", line 180, in <module>
    def receive_one_ping(sock: socket.socket, icmp_id: int, seq: int, timeout: int) -> float | None:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
>>>

None (as opposed to NoneType) isn't allowed until Python 3.10 -> that's what's up. See https://stackoverflow.com/a/76712732

Potential solutions -> use https://pypi.org/project/future-typing/ and specify that # -*- coding: future_typing -*- at the top of files before using | typing. Alternatively, use typing.Union instead.

vaab commented

Obvious workaround, as this was introduced by 4.0.6, forcing 4.0.5 will be enough to get through that.

That is true, and that is what we are doing for now. We thought this was worth posting/bringing up since this is a breaking change in a patch update

Sorry for the inconvenience. The unsupported type hints are removed in version 4.0.7. Can you test if it works?

Can confirm, doing pip install -U ping3 in the venv this failed in yesterday upgrades to 4.0.7 and am then able to import ping3 successfully.

(Also, thank you for the quick fix)