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

Auto-detect minimal Python version #688

Closed
kdeldycke opened this issue Jul 31, 2022 · 8 comments
Closed

Auto-detect minimal Python version #688

kdeldycke opened this issue Jul 31, 2022 · 8 comments

Comments

@kdeldycke
Copy link

kdeldycke commented Jul 31, 2022

My proposition is to have pyupgrade auto detect the minimal Python version targeted by a project and set by itself the --py3-plus / --py36-plus / (...) / --py311-plus option flags.

I hacked this autodetection feature in my GitHub workflows by inspecting the pyproject.toml.

Note this feature is also considered by black and discussed for mypy.

@SamirPS
Copy link

SamirPS commented Jul 31, 2022

If a new version of python is out you will need to modify the file no ? Can we erase the check <= 11 ?

@kdeldycke
Copy link
Author

kdeldycke commented Jul 31, 2022

Oh I see. I initially added that upper limit to make sure I'll not feed pyupgrade with options not recognized yet. Like in the time frame between new major Python versions and pyupgrade releases.

But I'm OK with removing that limit. It might be helpful to have it fail in this time-frame, as a reminder to have pyupgrade updated! :)

Just fixed this in kdeldycke/workflows@211f3a4

@SamirPS
Copy link

SamirPS commented Jul 31, 2022

Does PyUpgrade have a error if I enter --py-314-plus ?

@kdeldycke
Copy link
Author

It does:

❯ pyupgrade --py34-plus ./meta_package_manager/tests/test_cli_installed.py
usage: pyupgrade [-h] [--exit-zero-even-if-changed] [--keep-percent-format] [--keep-mock]
                 [--keep-runtime-typing] [--py3-plus] [--py36-plus] [--py37-plus] [--py38-plus]
                 [--py39-plus] [--py310-plus] [--py311-plus]
                 [filenames ...]
pyupgrade: error: unrecognized arguments: --py34-plus

@SamirPS
Copy link

SamirPS commented Jul 31, 2022

I thinks you change need to add your code here : https://github.com/asottile/pyupgrade/blob/main/pyupgrade/_main.py

@asottile
Copy link
Owner

no thanks -- that would involve reading configuration files of which I don't want anything to do with that complexity

@kdeldycke
Copy link
Author

OK no worries, I understand the policy of keeping pyupgrade to the essentials. I'll keep my hack confined to my GitHub workflows then.

@kdeldycke
Copy link
Author

kdeldycke commented Aug 1, 2022

Oh, and thanks @asottile for pyupgrade: it's a really cool project. Love it!

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

No branches or pull requests

3 participants