-
Notifications
You must be signed in to change notification settings - Fork 15
Type annotations #37
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
Type annotations #37
Conversation
This is my model for other similar packet issues (especially those with the cls parameter. As per Jeff's recommendations - we are ignoring the mypy warning on the format() method regarding bytes.
…based on new knowledge
with a little house cleaning of _xyz_packet
We are still getting mypy complaints about the Liskov Principle, and quarternion due to trying to return the sum of a bytes and an int. Need to flag this as an issue.
We are still getting mypy complaints about the Liskov Principle, and quarternion due to trying to return the sum of a bytes and an int. Need to flag this as an issue.
To avoid the dreaded Liskov Substitution Principle (thanks to mypy's fastidiousness)..
resolves: #31 |
Thanks for working on this! Nice find on that issue at line 44 in quaternion packet. I'm not super familiar with this library, but after having a look around I am thinking that might be a bug. The code it warns about is this:
Which does look to me like it would be trying add a bytes() and an int which as the error states isn't really allowed. I'm thinking it should be doing something like inside of here in the base class: Adafruit_CircuitPython_BluefruitConnect/adafruit_bluefruit_connect/packet.py Lines 143 to 147 in 863951f
And I'm guessing it hasn't been used in the right way for anyone to run into that issue (or at least not reported it if so). Regarding the other mypy warnings: It's okay at this point if we're not passing 100% of the mypy checks. This first pass is aimed at getting the "low hanging fruit" of function arguments and returns. Once we get all of that taken care of eventually we'll enable automatic mypy check and decide on a configuration for it at that point with which warnings will be active in the automated check |
Shall I go ahead and make the PR (it's currently in draft status) even with
the warning on quaternion_packet.py for line 44?
FYI: When I run mypy on the entire folder, I just have 3 errors, and only
the last one is related to the issue regarding quaternion_packet.py
I am wondering if we want to add the `to_bytes()` method on the
`self.checksum(partial_packet)`
```
adafruit_bluefruit_connect\packet.py:70: error: On Python 3 formatting
"b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is
desired behavior [str-bytes-safe]
adafruit_bluefruit_connect\packet.py:130: error: On Python 3 formatting
"b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this
is desired behavior [str-bytes-safe]
adafruit_bluefruit_connect\quaternion_packet.py:44: error: Missing
positional arguments "length", "byteorder" in call to "to_bytes" of "int"
[call-arg]
Found 3 errors in 2 files (checked 11 source files)
```
…On Wed, Apr 26, 2023, 4:35 PM foamyguy ***@***.***> wrote:
Thanks for working on this!
Nice find on that issue at line 44 in quaternion packet. I'm not super
familiar with this library, but after having a look around I am thinking
that might be a bug. The code it warns about is this:
partial_packet = struct.pack(
self._FMT_CONSTRUCT, self._TYPE_HEADER, self._x, self._y, self._z, self._w
)
return partial_packet + self.checksum(partial_packet)
Which does look to me like it would be trying add a bytes() and an int
which as the error states isn't really allowed.
I'm thinking it should be doing something like inside of here in the base
class:
https://github.com/adafruit/Adafruit_CircuitPython_BluefruitConnect/blob/863951fb2c4b375f627982d5dafefd46022a2440/adafruit_bluefruit_connect/packet.py#L143-L147
And I'm guessing it hasn't been used in the right way for anyone to run
into that issue (or at least not reported it if so).
Regarding the other mypy warnings: It's okay at this point if we're not
passing 100% of the mypy checks. This first pass is aimed at getting the
"low hanging fruit" of function arguments and returns. Once we get all of
that taken care of eventually we'll enable automatic mypy check and decide
on a configuration for it at that point with which warnings will be active
in the automated check
—
Reply to this email directly, view it on GitHub
<#37 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA5GKUUIMANNMTMBBFEVQ3LXDGWN3ANCNFSM6AAAAAAXM2NZGI>
.
You are receiving this because you authored the thread.Message ID:
<adafruit/Adafruit_CircuitPython_BluefruitConnect/pull/37/c1524198933@
github.com>
|
I do think it's okay to take the PR out of draft mode even though the line 44 thing is still outstanding. You can go ahead and make the change on line 44 if you want I think we'd be wrapping the self.checksum() inside of a call to We'll try to get someone with more familiarity with this library to take a look and verify that it makes sense. |
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.
One change needed for an import I believe.
The rest is looking good to me, but I do want to test it out on a device since there are a few changes that could possibly lead to different behavior. I'll report back if anything else comes up.
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.
This looks good to me now. Thanks again for taking this on @HundredVisionsGuy!
I pushed one commit to move that import into it's try block.
I tested all examples in the repo successfully with a Feather Sense and Android phone.
Updating https://github.com/adafruit/Adafruit_CircuitPython_BluefruitConnect to 1.2.9 from 1.2.8: > Merge pull request adafruit/Adafruit_CircuitPython_BluefruitConnect#37 from HundredVisionsGuy/type-annotations Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
Still failing mypy and I have some questions to pose regarding the quaternion_packet.py script on line 44.
I need to head home, but I will continue working on this in the coming days. Here are the mypy results: