ruff icon indicating copy to clipboard operation
ruff copied to clipboard

RFE: infer `target-version` from project metadata

Open scop opened this issue 2 years ago • 1 comments

target-version could in many cases be inferred from project metadata:

  • https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#requires-python
  • https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata-requires-python

Would be great to see ruff do that to eliminate one maintenance chore.

Black is moving toward doing that, too. The implementation over there is obviously somewhat different, because they still take a list of target versions whereas ruff takes the minimum one (which I think is the better, yet less flexible approach). Perhaps some of that work can be reused in ruff: https://github.com/psf/black/pull/3219

scop avatar Jan 20 '23 21:01 scop

Perhaps we can use https://github.com/konstin/pep440-rs from @konstin to power the version parsing?

charliermarsh avatar Jan 30 '23 22:01 charliermarsh

FYI: black#3219 was merged and shipped with black 23.1.0

ilkersigirci avatar Feb 03 '23 08:02 ilkersigirci

Black’s target version inference is currently broken: https://github.com/psf/black/issues/3581. I’m currently working on a fix and would be happy to port the solution to ruff. However, before that, #2519 should be decided.

manueljacob avatar Feb 24 '23 21:02 manueljacob

Nice! I'm happy to support target ranges, it's just not totally clear to me what rules they would affect and how.

charliermarsh avatar Feb 24 '23 23:02 charliermarsh

Black have different behaviors depending on the versions for example. Maybe ruff formatter should do the same.

JonathanPlasse avatar Feb 24 '23 23:02 JonathanPlasse

one thing to consider is that the behavior in https://github.com/psf/black/issues/3581 (>3.7 still implying 3.7 code styles) is most likely unintended and imho >3.7 (as opposed to >3.7.1 or >=3.7) should raise a warning (or you could emit linter errors for ruff's own configuration :D) EDIT: See also Y006 in flake8-pyi ("Use only < and >= for version comparisons. Comparisons involving > and <= may produce unintuitive results when tools do use the full sys.version_info tuple.")

konstin avatar Feb 25 '23 09:02 konstin

Should we close this issue?

JonathanPlasse avatar Mar 13 '23 18:03 JonathanPlasse

yep

konstin avatar Mar 13 '23 19:03 konstin

I created https://github.com/charliermarsh/ruff/issues/3487 to track inferring this info at runtime.

charliermarsh avatar Mar 13 '23 19:03 charliermarsh