krzema12 / kotlin-python

Python target for the Kotlin Programming Language. See https://github.com/krzema12/kotlin-python/tree/python-backend/python
https://discuss.kotlinlang.org/t/idea-python-backend/19852
48 stars 1 forks source link

Remove some unneeded parentheses, add them in some needed places #17

Closed SerVB closed 3 years ago

SerVB commented 3 years ago

Well, this is only a cosmetic change so not much changed there, but as it's ready, I propose to merge it. I will do integers support in future PRs.

krzema12 commented 3 years ago

QQ before I approve: does this change improve the correctness of arithmetics, or just makes the generated code prettier? No change in box tests coverage, but they may not catch certain cases.

SerVB commented 3 years ago

No change in arithmetics here.

Some unneeded parentheses are removed, this shouldn't affect correctness. It's to make code prettier.

Also, I've added optional parentheses to Call, Attribute, and Subscript since in general they can be needed there. For example, sometimes we need to calculate 2 + 2 and then call a method like .__add__(2). With this PR, it will be generated properly: (2 + 2).__add__(2). I hope this prevents some bugs in the future.