Skip to content

Commit

Permalink
fix uninitialized property
Browse files Browse the repository at this point in the history
When the robot is idle, parked at the base, and I call
`kh.get_device_properties(dev)`, I get back the following backtrace
(after removing some asyncio layers due to awaits):

   File "/nix/store/asiphbpiy2gmidfm3xbwcikayhs66289-python3-3.11.7/lib/python3.11/dataclasses.py", line 240, in wrapper
     result = user_function(self)
              ^^^^^^^^^^^^^^^^^^^
   File "<string>", line 3, in __repr__
 AttributeError: 'DeviceProperties' object has no attribute 'net_status'. Did you mean: 'net_stauts'?

What's particularly funny is that when run as `python -m asyncio`, to
get the `await` working in the REPL, the exception does not contain that
useful hint, and it looks like the following instead:

 >>> kh.get_device_properties(d[0])
 Traceback (most recent call last):
   File "/nix/store/asiphbpiy2gmidfm3xbwcikayhs66289-python3-3.11.7/lib/python3.11/concurrent/futures/_base.py", line 456, in result
     return self.__get_result()
            ^^^^^^^^^^^^^^^^^^^
   File "/nix/store/asiphbpiy2gmidfm3xbwcikayhs66289-python3-3.11.7/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
     raise self._exception
   File "/nix/store/asiphbpiy2gmidfm3xbwcikayhs66289-python3-3.11.7/lib/python3.11/asyncio/__main__.py", line 34, in callback
     coro = func()
            ^^^^^^
   File "<console>", line 1, in <module>
   File "/nix/store/asiphbpiy2gmidfm3xbwcikayhs66289-python3-3.11.7/lib/python3.11/dataclasses.py", line 240, in wrapper
     result = user_function(self)
              ^^^^^^^^^^^^^^^^^^^
   File "<string>", line 3, in __repr__
 AttributeError: 'DeviceProperties' object has no attribute 'net_status'

Anyway, the root cause was just a typo in DeviceProperties.__init__.

Fixes: e0065b6 Fix mutable default values in dataclass
  • Loading branch information
jktjkt committed Jan 27, 2024
1 parent 9e2c1ec commit 6c30e93
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion karcher/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class DeviceProperties:

def __init__(self, **kwargs):
setattr(self, 'cur_path', [])
setattr(self, 'net_stauts', DevicePropertiesNetwork())
setattr(self, 'net_status', DevicePropertiesNetwork())
setattr(self, 'order_total', DevicePropertiesOrderTotal())
setattr(self, 'privacy', DevicePropertiesPrivacy())
setattr(self, 'quiet_status', DevicePropertiesQuiet())
Expand Down

0 comments on commit 6c30e93

Please sign in to comment.