pyupgrade icon indicating copy to clipboard operation
pyupgrade copied to clipboard

an option to use the currently executing python version to determine what the rewrite target is

Open asottile opened this issue 2 years ago • 7 comments

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

asottile avatar Dec 12 '22 19:12 asottile

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.

hynek avatar Dec 15 '22 12:12 hynek

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

lev-blit avatar Jan 27 '23 14:01 lev-blit

no, unexplainable implicit behaviours are bad -- this will be an explicit setting

asottile avatar Jan 27 '23 14:01 asottile

perhaps a mutually exclusive option named --detect-version?

lev-blit avatar Jan 27 '23 14:01 lev-blit

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],
    )

DjLegolas avatar Jan 27 '23 23:01 DjLegolas

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.

hynek avatar Mar 15 '23 08:03 hynek

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

hugovk avatar Mar 15 '23 09:03 hugovk