Skip to content

MAINT: Fixes for prospective Python 3.10 and 4.0 #14364

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 3 commits into from
Aug 28, 2019

Conversation

hugovk
Copy link
Contributor

@hugovk hugovk commented Aug 26, 2019

We don't yet know if 3.10 or 4.0 will follow Python 3.9, but whichever it is, it will probably happen in 2020 (when Python 3.9 reaches beta).

There's some places in the codebase that slice the sys.version string, assuming the string is 3 characters long. This sort of thing will break on Python 3.10:

# in python3.10 this will report as '3.1' (should be '3.10')
python_version = sys.version[0:3]

# correct way to do this
python_version = '{}.{}'.format(*sys.version_info)

And also some places that would run Python 2 code on Python 4, such as:

# in python4 this will report as `False` (and suddenly run python2 code!)
is_py3 = sys.version_info[0] == 3

# correct way to do this
is_py3 = sys.version_info[0] >= 3

Found using https://github.com/asottile/flake8-2020:

$ pip install -U flake8-2020
...
$ flake8 --select YTT
./tools/swig/test/testFarray.py:18:41: YTT101: `sys.version[:...]` referenced (python3.10), use `sys.version_info`
./tools/npy_tempita/compat3.py:8:15: YTT201: `sys.version_info[0] == 3` referenced (python4), use `>=`
./numpy/distutils/command/build.py:41:54: YTT101: `sys.version[:...]` referenced (python3.10), use `sys.version_info`
./numpy/distutils/command/build_src.py:93:58: YTT101: `sys.version[:...]` referenced (python3.10), use `sys.version_info`
./numpy/core/setup.py:467:16: YTT201: `sys.version_info[0] == 3` referenced (python4), use `>=`
./numpy/testing/_private/parameterized.py:48:7: YTT201: `sys.version_info[0] == 3` referenced (python4), use `>=`

@charris charris changed the title Fix for Python 3.10 and 4 MAINT: Fixes for prospective Python 3.10 and 4.0 Aug 28, 2019
@charris charris merged commit 766a88d into numpy:master Aug 28, 2019
@charris
Copy link
Member

charris commented Aug 28, 2019

Thanks @hugovk .

@hugovk hugovk deleted the fix-flake8-2020 branch August 29, 2019 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants