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

Warn (or error) if targeting a higher version of Python than the one Black is running on #3144

Open
ichard26 opened this issue Jun 28, 2022 · 0 comments
Labels
C: parser How we parse code. Or fail to parse it. C: target version Related to --target-version, e.g. autodetection T: enhancement New feature or request

Comments

@ichard26
Copy link
Collaborator

ichard26 commented Jun 28, 2022

Is your feature request related to a problem? Please describe.

When formatting a file whose syntax requires a higher version of Python than the one Black is running on, Black fails (with a cannot use --safe with this file error). This is made more confusing because Black only fails when changes are made. If no changes are made, then everything seems to be OK and I won't ever know that the environment is faulty.

Describe the solution you'd like

It's still unclear whether target-version is an exact list of Python versions or just a minimum to target (see GH-751) but it would be dumb to check all of the target versions specified since many projects currently specify all of the Pythons they support (including us). We can only check the lowest specified which in a way kinda decides GH-751 for us.

It was also suggested to check the autodetected target version too. This is both easier and harder since there's only one target version to check (we get to avoid GH-751) but OTOH, we will probably want to warn only once which is a chore with multiprocessing.

Describe alternatives you've considered

  • Do nothing, this would continue to confuse users by letting Black's implementation details slip through without any messaging
  • Error out, maybe this is fine, but it sounds like a backwards compatibility break that's not worth it... especially since users could work around this by passing --fast skipping the AST equivalence check

Additional context

See also GH-3143 for additional discussion.

@ichard26 ichard26 added T: enhancement New feature or request C: parser How we parse code. Or fail to parse it. C: target version Related to --target-version, e.g. autodetection labels Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: parser How we parse code. Or fail to parse it. C: target version Related to --target-version, e.g. autodetection T: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant