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

Rewrite six.PY2 ternary #162

Open
asottile opened this issue Jun 11, 2019 · 10 comments
Open

Rewrite six.PY2 ternary #162

asottile opened this issue Jun 11, 2019 · 10 comments

Comments

@asottile
Copy link
Owner

2 if six.PY2 else 3

this one is going to be quite tricky I imagine

@graingert
Copy link
Contributor

I'd probably implement this as two steps, one to replace six.PY2 with False and another to remove unreachable branches

@graingert
Copy link
Contributor

@asottile here's a tool that does automatic dead code removal: coala/coala-bears#2000

@asottile
Copy link
Owner Author

@graingert note that this is already done for if statements, just not for ternary expressions -- no need to do two passes

vulture doesn't help here -- that dead code detection is similar to dead and doesn't at all help us to remove code

the detection part is simple, the "finding the end and beginning of the ternary expression" is hard

@graingert
Copy link
Contributor

it seems they've managed to get it to apply removals to dead code detections jendrikseipp/vulture#25

@asottile
Copy link
Owner Author

cool, but it doesn't help us here

@atugushev
Copy link
Contributor

Hm... The trickiest part is to rewrite:

3 if six.PY3 else 2

to

3

@asottile
Copy link
Owner Author

I think they're both nearly impossible given we don't properly know expression boundaries (though maybe the new python3.8 stuff helps?)

@ngnpope
Copy link

ngnpope commented Jul 7, 2021

I wonder if PEP 657 might help with this?

(It makes reference to branch differentiation in ternary statements w.r.t. coverage.)

@asottile
Copy link
Owner Author

asottile commented Jul 7, 2021

it does not help, we are not running code

@ngnpope
Copy link

ngnpope commented Jul 7, 2021

it does not help, we are not running code

Of course. 🤦🏻‍♂️ Sorry for the noise. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants