-
Notifications
You must be signed in to change notification settings - Fork 6
library updates! #1
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
Comments
My understanding is this is only a convention: OK Ha! It would appear we agree on this: |
In MicroPython/CircuitPython, adding the underscore actually prevents the name from going in the module dictionary. This is documented, but somewhat obscurely: http://circuitpython.readthedocs.io/en/2.x/docs/reference/constrained.html?highlight=underscore
http://circuitpython.readthedocs.io/en/2.x/docs/library/micropython.html?highlight=underscore
|
So it's a micro/cp thing only? Just did this with CP 2.1: SOME_CONST = 23
_SOME_CONST = 42 and then: >>> import foo
>>> dir(foo)
['SOME_CONST', '_SOME_CONST', '__name__', '__file__']
>>> foo._SOME_CONST
42
>>> foo._SOME_CONST = 99
>>> foo._SOME_CONST
99 |
i believe it is only when we mpy the file |
just tried. same behavior. |
Sorry, I was half-wrong. It's when you use
try that |
|
yep. that's it. from micropython import const
SOME_CONST = const(23)
_SOME_CONST = const(42)
def foo():
print("{0} {1}".format(SOME_CONST, _SOME_CONST)) REPL: >>> import foo
>>> dir(foo)
['const', 'SOME_CONST', 'foo', '__file__', '__name__']
>>> foo.foo()
23 42 |
How do we deal with non-integers? |
Use an underscore for consistency and as notice that it's meant to be private. Maybe someday const will work on other than integers. |
Is that the answer, or a suggestion? Sounds like we should add this to the design guide. |
i think both? :) we're updating the design guide ASAP, i just learned about this const stuff yesterday :D |
I think all three points in original post have been fixed, so closing. |
if const's have underlines, they wont be exposed outside the library, which i think makes sense for all the consts right? so instead of
TSL2561_DEFAULT_ADDRESS = const(0x39)
do
_TSL2561_DEFAULT_ADDRESS = const(0x39)
init should check the id and raise an RuntimeError if the chip is not found, the id() function can be inlined if you like - see https://github.com/adafruit/Adafruit_CircuitPython_BMP280/blob/master/adafruit_bmp280.py#L67
i know @tannewt mentioned changing lux to light but i actually just changed it back again (lux is a formal SI spec, light is just monotonic light measurements) so please make the property back to 'lux' (sorry!)
The text was updated successfully, but these errors were encountered: