Skip to content

Commit

Permalink
Added pytype None checks to local_usb.py.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 611147824
  • Loading branch information
OpenHTF Owners authored and copybara-github committed Feb 28, 2024
1 parent 2f7f3be commit 3903b6a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions openhtf/plugs/usb/local_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,17 @@ def port_path(self):
"""A string of the physical port of this device, like 'X-X.X.X'."""
return self._device_to_sysfs_path(self._device)

@property
def _checked_handle(self):
# _handle is initialized in constructor. It can't be None unless
# exceptions were thrown in the constructor
assert self._handle is not None
return self._handle

@usb_handle.requires_open_handle
def read(self, length, timeout_ms=None):
try:
return self._handle.bulkRead(
return self._checked_handle.bulkRead(
self._read_endpoint,
length,
timeout=self._timeout_or_default(timeout_ms))
Expand All @@ -136,7 +143,7 @@ def read(self, length, timeout_ms=None):
@usb_handle.requires_open_handle
def write(self, data, timeout_ms=None):
try:
return self._handle.bulkWrite(
return self._checked_handle.bulkWrite(
self._write_endpoint,
data,
timeout=self._timeout_or_default(timeout_ms))
Expand All @@ -150,8 +157,8 @@ def close(self):
return

try:
self._handle.releaseInterface(self._interface_number)
self._handle.close()
self._checked_handle.releaseInterface(self._interface_number)
self._checked_handle.close()
except libusb1.USBError:
_LOG.exception('USBError while closing handle %s:', self)
finally:
Expand Down

0 comments on commit 3903b6a

Please sign in to comment.