Skip to content

(🎁) Report better errors with syntax errors from the future #12357

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

Closed
KotlinIsland opened this issue Mar 15, 2022 · 2 comments · Fixed by #13197
Closed

(🎁) Report better errors with syntax errors from the future #12357

KotlinIsland opened this issue Mar 15, 2022 · 2 comments · Fixed by #13197
Labels

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Mar 15, 2022

look at this playground

even though "Python 3.10" (--python-version 3.10) is specified it still fails with a syntax error. This is not exactly obvious from the error:

main.py:2: error: invalid syntax
Found 1 error in 1 file (errors prevented further checking)

Perhaps something a little more telling could be said?

main.py:2: error: invalid syntax
main.py:2: note: perhaps this syntax comes from the future(🔮), you are only on ancient(🦕) python 3.9 after all
Found 1 error in 1 file (errors prevented further checking)

If should probably only get mentioned if you specify a --python-version higher than the interpreter.

@jhance
Copy link
Collaborator

jhance commented Mar 17, 2022

We would need the ability to parse future python in order to make this error message reliable, at which point there is really no benefit to this feature (as the only reason its a problem is that we can't parse future python).

A shorter note that includes the version but isn't opinionated on the "perhaps" bit might be better, as I'd hate to give a misleading error message maybe 95% of the time (given that most of my syntax errors are not because I'm using future syntax, but because I forgot a colon or something).

Another (breaking) option is to make using newer python_version than current version cause mypy to immediately error unless you pass say --unsafe-allow-future-python-version.

@KotlinIsland
Copy link
Contributor Author

That is true, but as mentioned in the op, if this message is only shown when invoked with a future python-version, it would be much more reliable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants