Skip to content

Add check if python_version was parsed as float in pyproject.toml #12558

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 5 commits into from
May 3, 2022

Conversation

Marcel-ICMC
Copy link
Contributor

@Marcel-ICMC Marcel-ICMC commented Apr 10, 2022

Fixes #12108

Passing python_version = 3.10 in a toml file without quotes gives this error message

pyproject.toml: [mypy]: python_version: Python 3.1 is not supported (must be 3.4 or higher)

This happens because the argument is parsed as a float and is converted into a string in mypy code, turning 3.10 into '3.1'. For other version like 3.8 this isn't a problem since it doesn't end in a zero.

I decided to leave python versions that don't end in a zero without error message, since it doesn't seem to have any problems regarding those cases. But for 3.10 a more clear message should leave fewer people confused about this specific issue.

Test Plan

Added a test for the case of python_version = 3.10 with the expected message at cmdline.test.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Can we move this check inside parse_version? We could also maybe give a more helpful message. E.g. something like

if minor < defaults.PYTHON3_VERSION_MIN[1]:
    msg = "..."
    if isinstance(s, float):
        msg += "You may need to put quotes around your version"

@Marcel-ICMC Marcel-ICMC requested a review from hauntsaninja May 3, 2022 00:12
Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 9f8b814 into python:master May 3, 2022
@Marcel-ICMC Marcel-ICMC deleted the toml-python-version-type branch May 7, 2022 18:50
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.

Friendlier error when 3.10 is parsed as float in pyproject.toml
3 participants