You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@andreadegiovine
You should systematically avoid syntax "if variable ... :" or "if not variable ..." everywhere in the code where variable has no defined type and you only want to prevent the case where variable is None because:
"if variable :" RETURN TRUE EVERY TIME variable is not None BUT ALSO when
variable is a bool with True value
variable is a not empty string
variable is an integer not 0
variable is a float not 0.0
variable is a list with at least one element
variable is a dictionary whith at least one element
and RETURN FALSE if variable is None (that is mostly the test you want to execute) BUT ALSO when
variable is a bool with False value
variable is an empty string
variable is an integer with value 0
variable is a float with value 0.0
variable is an empty list []
variable is an empty dictionary {}
which are mainly unwanted cases for not executing the clause.
and then using this syntax is the cause of many issues encountered, and to encounter...
I highly suggest to use preferentially explicit comparisons as
"variable is None", "variable is not None" (or "variable == None", "variable != None" if preferred) , when desired
As an example in function async def send_abrp_data(self) in base.py
(i do not use it yet but should have issues...)
if self._sensors.get("battery"):
tlm["soc"] = self._sensors.get("battery")
if self._sensors.get("speed"):
tlm["speed"] = self._sensors.get("speed")
.......
if self._sensors.get("autonomy"):
tlm["est_battery_range"] = self._sensors.get("autonomy")
tlm dictionary will not be updated with 0 values of battery nor speed nor autonomy
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
@andreadegiovine
You should systematically avoid syntax "if variable ... :" or "if not variable ..." everywhere in the code where variable has no defined type and you only want to prevent the case where variable is None because:
"if variable :" RETURN TRUE EVERY TIME variable is not None BUT ALSO when
and RETURN FALSE if variable is None (that is mostly the test you want to execute) BUT ALSO when
which are mainly unwanted cases for not executing the clause.
and then using this syntax is the cause of many issues encountered, and to encounter...
I highly suggest to use preferentially explicit comparisons as
"variable is None", "variable is not None" (or "variable == None", "variable != None" if preferred) , when desired
As an example in function async def send_abrp_data(self) in base.py
(i do not use it yet but should have issues...)
tlm dictionary will not be updated with 0 values of battery nor speed nor autonomy
All reactions