Skip to content
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

Friendlier error when 3.10 is parsed as float in pyproject.toml #12108

Closed
jamesbraza opened this issue Jan 31, 2022 · 9 comments · Fixed by #12558
Closed

Friendlier error when 3.10 is parsed as float in pyproject.toml #12108

jamesbraza opened this issue Jan 31, 2022 · 9 comments · Fixed by #12558
Labels
bug mypy got something wrong good-first-issue topic-error-reporting How we report errors

Comments

@jamesbraza
Copy link
Contributor

Bug Report

Running mypy with Python 3.10 and python_version in the config file has a few wrong behaviors:

  1. It lists mypy must be 3.4 or higher (it should say 3.6)
  2. It truncates Python 3.10 to 3.1
  3. It outputs a message when there shouldn't be one (you can invoke mypy with Python 3.10)

To Reproduce

Here is a subset of my pyproject.toml:

[tool.mypy]
# SEE: http://mypy.readthedocs.io/en/latest/config_file.html#config-file

# Specifies the Python version used to parse and check the target program.
python_version = 3.10

# Enables PEP 420 style namespace packages.
namespace_packages = true

I invoke mypy via: mypy -p namespacepkg

Expected Behavior

Not to raise this message.

Actual Behavior

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

Your Environment

  • Mypy version used: 0.931
  • Mypy command-line flags: n/a
  • Mypy configuration options from mypy.ini (and other config files): see above pyproject.toml
  • Python version used: 3.10.2
  • Operating system and version: macOS v11.5.1 Big Sur
@jamesbraza jamesbraza added the bug mypy got something wrong label Jan 31, 2022
@JelleZijlstra
Copy link
Member

You need to quote it as "3.10", because it's a float! We can probably put a special-case message here to make that clear though.

@jamesbraza
Copy link
Contributor Author

Changing it to:

# Specifies the Python version used to parse and check the target program.
python_version = "3.10"

Indeed fixes the problem. In hindsight it makes total sense. Yeah maybe a special message would be a good idea, thank you!

@hauntsaninja hauntsaninja changed the title False positive for Python 3.10: python_version: Python 3.1 is not supported Friendlier error when 3.10 is parsed as float in pyproject.toml Feb 3, 2022
@radioactive11
Copy link

@hauntsaninja Being a first-time contributor, I would like to work on this issue. Any suggestions on where I can start with?

@nakatomotoi
Copy link
Contributor

@hauntsaninja @jamesbraza
May I work on this issue?

@jamesbraza
Copy link
Contributor Author

@radioactive11 @nakatomotoi yes either of you can! Just make a fork of mypy, cut a branch, try to implement a solution + add test(s) proving it works (see CONTRIBUTING.md for how to run tests), and open a PR back to mypy's master branch.

@radioactive11
Copy link

@jamesbraza Sure!

@radioactive11
Copy link

@jamesbraza Should I add a special message when the version mentioned has two decimal digits or a general one?

@JelleZijlstra
Copy link
Member

There should be a message specific to this case (though it should also cover 3.11 and other future versions).

@Loriasun
Copy link

@hauntsaninja @jamesbraza Hi there, can I still work on this one?

JelleZijlstra pushed a commit that referenced this issue May 3, 2022
…2558)

Fixes #12108

Co-authored-by: Marcel-ICMC <marcel.lima@usp.br>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
chuanhao01 added a commit to chuanhao01/python-package-template that referenced this issue Feb 9, 2023
Description
mypy parses the python version as float instead of a string
python/mypy#12108
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong good-first-issue topic-error-reporting How we report errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants