python-trio / trio-websocket

WebSocket client and server implementation for Python Trio
MIT License
70 stars 26 forks source link

trio_websocket makes wrong assumptions about `trio.__version__` #178

Closed mgorny closed 1 year ago

mgorny commented 1 year ago
$ python3.11 -c 'import trio_websocket'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.11/site-packages/trio_websocket/__init__.py", line 1, in <module>
    from ._impl import (
  File "/usr/lib/python3.11/site-packages/trio_websocket/_impl.py", line 33, in <module>
    _TRIO_MULTI_ERROR = tuple(map(int, trio.__version__.split('.'))) < (0, 22, 0)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '0+dev'

Apparently it assumes that trio.__version__ will always be X.Y.Z and doesn't support other valid PEP 440 versions, effectively causing it to fail when a development version of trio is used (but the same would also happen with release candidates, etc.).

belm0 commented 1 year ago

Thank you. Rather than add some parsing library dependency or large regex, I think looking at the first two numbers will cover likely cases.

tuple(map(int, trio.__version__.split('.')[:2])) < (0, 22)

mgorny commented 1 year ago

Yes, I think that should be good enough. Thanks!

belm0 commented 1 year ago

the fix is published to pypi (v0.10.3)