Skip to content

Python compatibility clarifications #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ os:
- linux # Travis does not support Python on OSX or Windows. Should we migrate to a different CI service?

python:
- 3.5
- 3.6
- 3.7-dev # TODO: Replace with plain "3.7" when supported by Travis
# - 3.8-dev # TODO: Compatibility issues with MyPy, see https://travis-ci.org/UAVCAN/pydsdl/jobs/519988157
- '3.5.3' # Oldest supported version
- '3.5'
- '3.6'
- '3.7-dev' # TODO: Replace with plain "3.7" when supported by Travis
# - '3.8-dev' # TODO: Compatibility issues with MyPy, see https://travis-ci.org/UAVCAN/pydsdl/jobs/519988157

before_script:
- pip install -r requirements.txt
- pip install coveralls # Intentionally removed from requirements.txt because it's only useful in the CI environment

script:
- python --version
- ./test.sh
- coveralls # Publish the coverage stats online.
- git clone https://github.com/UAVCAN/dsdl --branch=uavcan-v1.0 dsdl-test # TODO: Switch to master once v1.0 is merged
Expand Down
28 changes: 25 additions & 3 deletions pydsdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,33 @@
import os as _os
import sys as _sys

if _sys.version_info[:2] < (3, 5): # pragma: no cover
print('A newer version of Python is required', file=_sys.stderr)
# The original intent was to support Python 3.5 and newer; however, we have discovered a bug in the static typing
# library in Python 3.5.2 which makes the library quite unusable: when importing, the typing module would throw
# "TypeError: This Callable type is already parameterized." from the expression module. The problem does not appear
# in Python 3.5.3 or any newer versions; it is fixed in the upstream here: https://github.com/python/typing/pull/308.
# This is how you can reproduce it in REPL; first, the correct behavior that can be observed in Python 3.5.3+:
# >>> import typing
# >>> T = typing.TypeVar('T')
# >>> G = typing.Callable[[], T]
# >>> G[int]
# typing.Callable[[], int]
# And this is what you get in Python 3.5.2-:
# >>> import typing
# >>> T = typing.TypeVar('T')
# >>> G = typing.Callable[[], T]
# >>> G[int]
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# File "/usr/lib/python3.5/typing.py", line 815, in __getitem__
# raise TypeError("This Callable type is already parameterized.")
# TypeError: This Callable type is already parameterized.
_min_supported_python_version = 3, 5, 3
if _sys.version_info[:3] < _min_supported_python_version: # pragma: no cover
print('This package requires a Python version', '.'.join(map(str, _min_supported_python_version)), 'or newer',
file=_sys.stderr)
_sys.exit(1)

__version__ = 0, 7, 3
__version__ = 0, 8, 0
__license__ = 'MIT'

# Our unorthodox approach to dependency management requires us to apply certain workarounds.
Expand Down