-
Notifications
You must be signed in to change notification settings - Fork 52
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
[RSDK-878] Typechecking #512
Conversation
Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!
|
@randhid @penguinland FYI this PR removes the subclassing from GPIOPin, AnalogReader, DigitalIterrupt |
with open(dest, "wb") as file: | ||
file.write(data) | ||
stream: Stream[GetInvoicePdfRequest, GetInvoicePdfResponse] | ||
async with self._billing_client.GetInvoicePdf.open(timeout=timeout, metadata=self._metadata) as stream: |
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.
type checking surfaced this issue, where we weren't streaming the response properly
myst-nb = [ | ||
{version = "<1.0.0", python = "<3.9"}, | ||
{version = ">=1.0.0", python = ">=3.9"}, | ||
] | ||
sphinx-autoapi = [ | ||
{version = "<3.0.0", python = "<3.9"}, | ||
{version = ">=3.0.0", python = ">=3.9"}, | ||
] |
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.
Updating deps only support >3.9
@@ -44,6 +45,8 @@ def getLogger(name: str) -> logging.Logger: | |||
|
|||
|
|||
def addHandlers(logger: logging.Logger): | |||
logger.handlers.clear() |
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 is to fix an issue where logs were getting doubled if the level was changed
@@ -41,15 +41,15 @@ async def get_position(self, *, timeout: Optional[float] = None) -> Pose: | |||
response: GetPositionResponse = await self.client.GetPosition(request, timeout=timeout) | |||
return response.pose | |||
|
|||
async def get_point_cloud_map(self, *, timeout: Optional[float] = None) -> List[GetPointCloudMapResponse]: | |||
async def get_point_cloud_map(self, *, timeout: Optional[float] = None) -> List[bytes]: |
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.
type checking surfaced these incorrect return types
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.
Nice! A couple questions and one small change, otherwise lgtm!
src/viam/app/app_client.py
Outdated
return response.url | ||
await stream.recv_trailing_metadata() # causes us to throw appropriate gRPC error. |
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.
It looks like this got inverted from how it was before? we want to recv_trailing_metadata()
to throw an error, when response
is None
.
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.
Not sure why I changed it, but isn't this functionally the same?
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.
🤦 yes you're absolutely right, read it too quickly and thought the if
statements were equivalent.
I do have a slight preference for either leaving it the way it was or updating the equivalent logic in data_client.py
and audo_input/client.py
just to all be consistent, but I don't feel strongly enough to hold off release.
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.
LGTM. It's cool to see the errors that type checking picked 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.
lgtm!
Add typechecking to the python SDK. I chose pyright over mypy for a few reasons:
We will likely still want to eventually move over to mypy, but this is a great starting place for us.
Some notes on why I did what I did:
__eq__
functions__eq__
methods that were typed to the type of self, it was an incorrect overrideSUBTYPE
in resourcesSUBTYPE
field is required for all resource types (anything that extends fromResourceBase
). When we actually implement that in our concrete subtypes, we want it to beFinal
. However, since the original abstract definition is notFinal
(because it's abstract), the typechecker views it as an incompatible override. So I ignore it**__
in method functions**kwargs
as parameters, those need to be included in the client to make a valid override. However, those would go unused. So I added**__
to signify unused kwargsself.get_resource
, it's correctly typedComponentBase
from_robot