python-decompile3 icon indicating copy to clipboard operation
python-decompile3 copied to clipboard

remove "(" ")" when tuple used in return or in LHS of assignment?

Open rocky opened this issue 6 years ago • 2 comments

rocky avatar Jul 01 '19 17:07 rocky

Is this still wanted? Happy to work on that @rocky.

(I agree that

a, b = foo()

looks cleanear and more pythonic than

(a, b) = foo()

so this looks like a good change. I've also reproduced this issue with the current master. The only thing I worry about is that this may require significant grammar changes (to detect this specific example of (tuple) = somethint), but I'll try.

msm-code avatar Feb 18 '23 14:02 msm-code

@msm-code actually, I believe this is just a matter of going over operator precedences and possibly the semantic rules that mention these so that LHS doesn't need a parenthesis around it in the context of an assignment statement. And if a rule is explicitly adding "(" .. ")" in a rule or action, then remove that and allow precedence to do its thing instead.

I have seem something like this come up in the latest not-public version where I have been revising things more from the ground up.

So if you get started there, I can try to fold in precedence changes from this version, and I think there were some code changes or grammar changes to ensure that "expr" gets used.

"expr" is the single location where precedence is used to add optional parenthesis.

rocky avatar Feb 18 '23 14:02 rocky