Skip to content

Suggest using a newer Python version if possibly needed #13197

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 4 commits into from
Jul 27, 2022

Conversation

hauntsaninja
Copy link
Collaborator

Fixes #12357

@github-actions

This comment has been minimized.

@KotlinIsland
Copy link
Contributor

Could the output mention the current interpreter? the original issue was on the playground using 3.10 with python-version 3.11, but you wouldn't know it unless you inspected the verbose logs.

# flags: --python-version 3.99
this is what future python looks like public static void main String[] args await goto exit
[out]
main:2: error: invalid syntax; maybe you need to use a newer version of Python to run mypy?
Copy link
Member

@sobolevn sobolevn Jul 20, 2022

Choose a reason for hiding this comment

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

I agree with @KotlinIsland, I think we need to show versions to users and explain what is going on with more details. Because it is confusing indeed.

Suggested change
main:2: error: invalid syntax; maybe you need to use a newer version of Python to run mypy?
main:2: error: invalid syntax; maybe you need to use a newer version of Python to run mypy?
python3.10 cannot parse syntax from python3.99

Copy link
Contributor

Choose a reason for hiding this comment

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

What about we update the ast module in older versions of python to be able to parse newer python?

Could also make it an installable package.

Copy link
Member

@sobolevn sobolevn Jul 20, 2022

Choose a reason for hiding this comment

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

I maintain too many ast hacks to agree 🙂
Example: https://github.com/wemake-services/wemake-python-styleguide/tree/master/wemake_python_styleguide/compat

Probably using a better message is the best we can do in the long run.
Trying to parse future versions of python with older ones is way out of our main goal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, agreed that's a nice to have. But I don't have time to spend wiring up the test infra just to allow a version specific error message for this.
If this is an improvement over the status quo, let's merge, otherwise I'll close this and someone else can look into shipping it with a better error message :-)

Copy link
Collaborator Author

@hauntsaninja hauntsaninja Jul 20, 2022

Choose a reason for hiding this comment

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

That's basically what typed-ast was, and it was a bit of a pain to maintain (#6545)

@github-actions

This comment has been minimized.

# flags: --python-version 3.99
this is what future python looks like public static void main String[] args await goto exit
[out]
main:2: error: invalid syntax; you likely need to run mypy using a newer version of Python.
Copy link
Collaborator

Choose a reason for hiding this comment

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

A few nits:

  • Drop the final dot, for consistency?
  • What about only showing the target version in the error message, such as "... you likely need to run mypy using Python 3.99 or newer"? This should be easy to do, I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, fixed both

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

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

@hauntsaninja hauntsaninja merged commit 5f85898 into python:master Jul 27, 2022
@hauntsaninja hauntsaninja deleted the new-py branch July 27, 2022 03:34
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.

(🎁) Report better errors with syntax errors from the future
4 participants