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

Feature Request: Exclude lines from conversion with a comment #574

Closed
CarliJoy opened this issue Nov 30, 2021 · 5 comments
Closed

Feature Request: Exclude lines from conversion with a comment #574

CarliJoy opened this issue Nov 30, 2021 · 5 comments

Comments

@CarliJoy
Copy link

It would be nice if line/block could be excluded from upgrading with a comment like # nopyupgrade or # start nopyupgrade in order to keep specific lines:
i.e. dict(foo="bar") when intended.

We are discussion to include pyupgrade in our teams pipeline but some team mate made this an requirement.

Would / Will this be possible in the future?

Have a glimps look in the source I don't see how to introduce this easily :-/

Any thoughts?

@CarliJoy CarliJoy changed the title Exclude lines from conversion with a comment Feature Request: Exclude lines from conversion with a comment Nov 30, 2021
@asottile
Copy link
Owner

asottile commented Nov 30, 2021

no sorry, pyupgrade is an opinionated tool if you don't like the opinions don't use it

the whole point is that there's no discussions

@asottile
Copy link
Owner

also dict(foo="bar") does not get rewritten and it's slower than a literal

@CarliJoy
Copy link
Author

Understood. Thanks for the fast feedback :)

@JacobHayes
Copy link

JacobHayes commented Jan 11, 2022

I greatly appreciate the opinionated nature, but wonder if there might still be a valid use for this. For example, I'm working with code that explicitly inspects (user defined) type hints. In tests I confirm tuple[int] and Tuple[int] are both handled properly. I'd like for the rest of my code to use new hint syntax, but spot-disable in tests. Otherwise, running pyupgrade --keep-runtime-typing --py39-plus changed both to tuple[int], triggering a test failure + reduced coverage. Tuple = getattr(typing, "Tuple") works as a questionable workaround (without having to ignore tests/ completely). 😅

This seems a bit different than say black as there may be runtime observable differences that may need an escape hatch. However - if you still prefer this not be added, I can understand that too!

@asottile
Copy link
Owner

you're looking for --keep-runtime-typing

Repository owner locked as resolved and limited conversation to collaborators Jan 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants