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

Allow stubs to use newer syntax than 3.7 #13500

Merged
merged 1 commit into from
Aug 24, 2022

Conversation

hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Aug 24, 2022

Fixes #13499

Today this code reads like "stubs should all target 3.7" and this
is indeed how typeshed operates. But authors of pyi other than typeshed
should probably be allowed to choose what Python version they're
targetting. Since typeshed runs checks against 3.7, this should not
cause testing regressions for typeshed.

This code goes back to #3000 back in the typed_ast days, when this
allowed stubs to use much newer syntax features than the base Python
version, so in some ways this is in the spirit of the original code.

Fixes python#13499

Today this code reads like "stubs should all target 3.7" and this
is indeed how typeshed operates. But authors of pyi other than typeshed
should probably be allowed to choose what Python version they're
targetting.

This code goes back to python#3000 back in the typed_ast days, when this
allowed stubs to use much newer syntax features than the base Python
version, so in some ways this is in the spirit of the original code.
@hauntsaninja
Copy link
Collaborator Author

hauntsaninja commented Aug 24, 2022

Also note that OP is on PyPy. feature_version has been pretty permissive in CPython, although I recently made some PRs that will tighten things up, e.g. python/cpython#94996.

@github-actions
Copy link
Contributor

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

@JelleZijlstra
Copy link
Member

Is it worth adding a test that uses newer syntax in a stub file? (We'd have to skip the test on older versions.)

@hauntsaninja
Copy link
Collaborator Author

hauntsaninja commented Aug 24, 2022

Can't add one for pos-only because whether or not that is parsed now depends on micro version of CPython (and in particular, wheels repo tests with micro version 0). I think walrus is rejected without feature version in all versions of 3.8? But you wouldn't use that in a stub. Conclusion: not worth it

@hauntsaninja
Copy link
Collaborator Author

I did test locally though

@JelleZijlstra
Copy link
Member

I guess the only other stub-relevant syntactic change is PEP 646's *args: *Ts but that's only in 3.11.

@pedrospdc
Copy link

Oddly enough, numpy type checking does work if I run it in my ARM64 built image, but not when I run it in my AMD64 image.

jhance pushed a commit that referenced this pull request Sep 9, 2022
Fixes #13499

Today this code reads like "stubs should all target 3.7" and this
is indeed how typeshed operates. But authors of pyi other than typeshed
should probably be allowed to choose what Python version they're
targetting. Since typeshed runs checks against 3.7, this should not
cause testing regressions for typeshed.

This code goes back to #3000 back in the typed_ast days, when this
allowed stubs to use much newer syntax features than the base Python
version, so in some ways this is in the spirit of the original code.
jenshnielsen added a commit to jenshnielsen/Qcodes that referenced this pull request Sep 12, 2022
This can be reverted once a mypy version with python/mypy#13500 is out
jenshnielsen added a commit to jenshnielsen/Qcodes that referenced this pull request Sep 12, 2022
This can be reverted once a mypy version with python/mypy#13500 is out
jenshnielsen added a commit to jenshnielsen/Qcodes that referenced this pull request Sep 12, 2022
This can be reverted once a mypy version with python/mypy#13500 is out
@TheMellyBee
Copy link

Has this been released yet?

@hauntsaninja
Copy link
Collaborator Author

No, follow #13385

davidt0x added a commit to davidt0x/brainiak that referenced this pull request Sep 19, 2022
Pin mypy to github version until fix for python 3.10.7 is released.
python/mypy#13500
@jepler
Copy link

jepler commented Sep 25, 2022

Is there any insight into why the release of python 3.10.7 caused many projects to start seeing this diagnostic?

@AlexWaygood
Copy link
Member

AlexWaygood commented Sep 25, 2022

Is there any insight into why the release of python 3.10.7 caused many projects to start seeing this diagnostic?

Python 3.10.7 includes python/cpython#95935, which means that the latent bug in mypy (that's been around for a while) suddenly becomes a big problem

@jepler
Copy link

jepler commented Sep 25, 2022

Thanks, that makes sense now.

@matoro
Copy link

matoro commented Sep 26, 2022

Oddly enough, numpy type checking does work if I run it in my ARM64 built image, but not when I run it in my AMD64 image.

I also noticed that this appears to be somewhat architecture-dependent for some reason.

@hauntsaninja
Copy link
Collaborator Author

It's not architecture dependent, it's only about the specific version of Python you have in your image. If you have Python 3.10.7 you'll see the error, if you have Python 3.10.6 you won't. In all cases, upgrading to mypy 0.981 will fix.

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.

pypy3.9 - SyntaxError due to positional only arguments in stubfile
7 participants