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

const-folding #91

Closed
mqyhlkahu opened this issue Aug 5, 2023 · 2 comments
Closed

const-folding #91

mqyhlkahu opened this issue Aug 5, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@mqyhlkahu
Copy link

A possible improvement would be const-folding expressions that would be shorter as a constant value.

Example:

SOME_VARIABLE = (((123 * 456) + 789) // 10) & 0xabcdef

can be transformed into

SOME_VARIABLE=1063

Note that the Python interpreter will do this at compile-time anyway, so it won't have any effect on the code that is actually run.

>>> import dis
>>> dis.dis("(((123 * 456) + 789) // 10) & 0xabcdef")
  0           0 RESUME                   0

  1           2 LOAD_CONST               0 (1063)
              4 RETURN_VALUE
@dflook
Copy link
Owner

dflook commented Sep 2, 2023

Thanks for creating an issue @kotnen, keep any eye out for this in the next release 😄

@dflook dflook added the enhancement New feature or request label Sep 2, 2023
@dflook
Copy link
Owner

dflook commented Sep 28, 2024

This was included in v2.10.0

@dflook dflook closed this as completed Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants