-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix _bleio
doc comments
#9540
Fix _bleio
doc comments
#9540
Conversation
I have almost finished fixing the typing of BLE lib and didnt find any more issues with respect to _bleio stubs, ready for review here (: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for workign on this.
This also lead me to seeing
__init__
is not defined... Does that mean that trying to runCharacteristic()
will raise? If so, should we perhaps change the type hint from-> None
to-> NoReturn
or the like?
Yes, calling the constructor raises an exception:
>>> from _bleio import Characteristic
>>> c = Characteristic()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'Characteristic' instances
The __init__()
signature is not shown directly in the documentation, but the .pyi
stubs file has it. See the documentation here:
https://docs.circuitpython.org/en/latest/shared-bindings/_bleio/index.html#bleio.Characteristic.
I don't remember why we put that comment in the __init()__
docstring, when there is no init. Locally I changed the doc to remove the __init()__
signature and put its comment into the class comment, and that seems to work fine: the doc and the stubs build without errors.
//| class Characteristic:
//| """Stores information about a BLE service characteristic and allows reading
//| and writing of the characteristic's value.
//|
//| There is no regular constructor for a `Characteristic`. A new local `Characteristic` can be created
//| and attached to a Service by calling `add_to_service()`.
//| Remote Characteristic objects are created by `Connection.discover_remote_services()`
//| as part of remote Services.
//| """
//|
//| def add_to_service(
Note the extra blank line after the closing """
, which was added by the pre-commit check.
Also note I put backticks around "Characteristic" in the comment.
Removing the __init()__
signature should also be done for _bleio.Descriptor
and other classes that don't have a public constructor.
My concern was not really showing vs not showing the Skipping it on the doc-comment, {MyPy/Intellisense/whatever} would assume we have a "default" However, i've been testing locally for a bit and can't find a way to "describe" this behavior such that MyPy can give useful feedback in this aspect. In fact, doing it a I think the best idea is to keep the |
OK, I see what you mean. In pure Python, I think you always have an This is interesting: https://stackoverflow.com/questions/46779046/correct-type-annotation-for-init. It says that the return type annotation could just be omitted. |
Im not sure about this, but i think that adding The idea for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All set after some side discussion on this.
Draft because I will be fixing anything else I find while i working on
Adafruit_CircuitPython_BLE
's type hintsI just found out this because
mypy
complained thatadd_to_service
was missing a positional arg (self
andservice
were expected based on comment, but it really is a classmethod and onlyservice
has to be passed in)This also lead me to seeing
__init__
is not defined... Does that mean that trying to runCharacteristic()
will raise? If so, should we perhaps change the type hint from-> None
to-> NoReturn
or the like?