pyupgrade
pyupgrade copied to clipboard
an option to use the currently executing python version to determine what the rewrite target is
discussed a bit with @hynek on twitter -- mostly need to bikeshed a name
basically an alternative to the --py36-plus options but instead uses the currently running python
For posterity: my main motivation here is that I use pyupgrade 100% via pre-commit and currently have to change both the default Python version to run all tools and the target version for pyupgrade whenever I upgrade an app to a newer Python version.
maybe have a fallback of detected version if no --py36-plus option is specified?
seems like changing the min_version argument to have a default of sys.version_info[0:2] would do the trick
no, unexplainable implicit behaviours are bad -- this will be an explicit setting
perhaps a mutually exclusive option named --detect-version?
I think that we can use a parameter --currpy-plus which will set min_version = sys.version_info[:2].
The name is still not final 🤣
Something like:
parser.add_argument(
'--currpy-plus',
action='store_const', dest='min_version', const=sys.version_info[:2],
)
OK I think I would like to modify my feature request!
pyupgrade --requires-python-plus that looks at my packaging metadata and uses the requires-python field – for all I care just by parsing pyproject.toml and setup.cfg. That's what Black is doing now and kinda is what one would expect? I would go as far as saying that should be the default.
Using requires-python from pyproject.toml would be nice but it's been rejected before (https://github.com/asottile/pyupgrade/issues/688#issuecomment-1200443121):
no thanks -- that would involve reading configuration files of which I don't want anything to do with that complexity
Also:
- https://github.com/asottile/pyupgrade/issues/511
- https://github.com/asottile/pyupgrade/issues/550
- https://github.com/asottile/pyupgrade/issues/795