265 )
266
267 @property
268 def icon(self) -> str | None:269 """Icon to use in the frontend."""
270 # Only the gas usage sensor needs an icon as the others inherit from their device class
271 if self.resource.classifier == "gas.consumption":
According to PEP8, if any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None
, and an explicit return statement should be present at the end of the function (if reachable).
Good:
def foo(x):
if x >= 0:
return math.sqrt(x)
else:
return None
def bar(x):
if x < 0:
return None
return math.sqrt(x)
Bad:
def foo(x):
if x >= 0:
return math.sqrt(x)
def bar(x):
if x < 0:
return
return math.sqrt(x)