-
Notifications
You must be signed in to change notification settings - Fork 1.1k
aiorepl: Fix usage of const function #693
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
Conversation
|
@mishal compiles to whereas compiles to You can see that (I'm not actually sure why we provide |
|
OK, thanks for info. It looks like that almost every lib uses |
@mishal Could you clarify what you mean by "almost every lib"? Thanks |
|
sorry... I wanted to say, that (If I understand it correctly) lib authors trying to optimize their code using I use i2c eeprom in my project:
Also other authors use see: https://github.com/search?q=%22from+micropython+import+const%22&type=code The docs say that micropython.const is what should be used: https://docs.micropython.org/en/latest/library/micropython.html?highlight=const#micropython.const |
|
The optimisation takes place if you use The only issue is if you write Sorry I did not explain this very well -- and it's kind of confusing because these snippets are not the same, despite what regular Python semantics would tell you: from micropython import const
X = const(1) # Does the optimisationimport micropython
X = micropython.const(1) # Does not do the optimisationA third example: from micropython import const as c
X = c(1) # Does not do the optimisationWhat's going on here is that the compiler specifically has a rule that detects the exact function name As far as I can see, both the examples linked from @peterhinch are doing the correct thing, and your github search doesn't show any issues -- doing However, a different github search https://github.com/search?q=%22micropython.const%22&type=code shows many examples of the wrong thing.
I don't think they do? They give a code example of just using plain |
|
@jimmo thanks, now I get it! This PR was about getting my IDE happy... there's no global const function in CPython. In your airepl.py you don't import the const from micropython module... |
aiorepl: Fix usage of const function