Avoid warning in Gateway.__del__#442
Conversation
This test was emitting a warning, which came from garbage collection on Gateway objects that failed in `__init__`.
|
|
||
| def __del__(self): | ||
| if ( | ||
| if hasattr(self, "_asynchronous") and ( |
There was a problem hiding this comment.
In case the property changes implementation, should maybe check the referenced name instead of an implementation detail.
| if hasattr(self, "_asynchronous") and ( | |
| if hasattr(self, "asynchronous") and ( |
There was a problem hiding this comment.
Let me check that. I assumed hasattr always returned true for properties, but maybe not if they raise an AttributeError?
There was a problem hiding this comment.
OK switched to use asynchronous and there's no warning, but I have no idea why it's working. It seems like hasattr does always evaluate true in this case:
In [1]: class Foo:
...: @property
...: def a(self):
...: return self._a
...:
In [2]: hasattr(Foo, "a")
Out[2]: Trueso I would expect the warning to be back when using the property name. But I guess it doesn't really matter, as long as it works.
There was a problem hiding this comment.
You're checking on the class above (which will always work), when what you meant to do was check on an instance
>>> hasattr(Foo, "a")
True
>>> hasattr(Foo(), "a")
Falsehasattr is basically:
def hasattr(x, name):
try:
getattr(x, name)
return True
except AttributeError:
return False|
Test failure is a known CI issue. Merging, thanks Tom! |
This test was emitting a warning, which came from garbage collection on
Gateway objects that failed in
__init__.