Skip to content

Conversation

@hugovk
Copy link
Contributor

@hugovk hugovk commented Jan 17, 2020

When dealing with version numbers, it's generally safer to use the sys.version_info tuple that the sys.version string.

>>> sys.version
'3.7.5 (default, Nov  1 2019, 02:16:32) \n[Clang 11.0.0 (clang-1100.0.33.8)]'
>>> sys.version[0]
'3.7'
>>> fake_version10_info = '10.0.5 (default, Nov  1 2019, 02:16:32) \n[Clang 11.0.0 (clang-1100.0.33.8)]'
>>> fake_version310_info[0]
'1'

Similarly:

>>> sys.version
'3.7.5 (default, Nov  1 2019, 02:16:32) \n[Clang 11.0.0 (clang-1100.0.33.8)]'
>>> sys.version[2]
'7'
>>> fake_version3_10_info = '3.10.5 (default, Nov  1 2019, 02:16:32) \n[Clang 11.0.0 (clang-1100.0.33.8)]'
'1'

py_minor_version = sys.version[2] isn't used anywhere, so it can be removed. If it is needed in the future, prefer sys.version_info.minor or sys.version_info[2].

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

@seperman
Copy link
Owner

Cool. Thanks for the info and the PR @hugovk !

@seperman seperman changed the base branch from master to dev January 30, 2020 18:58
@seperman seperman merged commit ca5767b into seperman:dev Jan 30, 2020
@hugovk hugovk deleted the fix-flake8-2020 branch January 30, 2020 19:01
@hugovk
Copy link
Contributor Author

hugovk commented Jan 30, 2020

You're welcome, thanks for maintaining!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants