dls-controls / aioca

Asynchronous Channel Access client for asyncio and Python using libca via ctypes
Apache License 2.0
6 stars 3 forks source link

Make `bool(CANothing)` always return True #45

Open coretl opened 1 week ago

coretl commented 1 week ago

https://github.com/dls-controls/aioca/blob/12a0a68c249b90cd375b9432ed438c7a7e85ab97/aioca/_catools.py#L92-L93

Causes issues with various python internals, like concurrent.futures.result which does: https://github.com/python/cpython/blob/d5a8d4b19670b930cd6cb5e18e267877ebe49233/Lib/concurrent/futures/_base.py#L399

So if we put a CANothing in as a result it shows as no exception...

coretl commented 1 week ago

Suggestion:

coretl commented 1 week ago

Can't make the warning in aioca as this will be too noisy because of the concurrent.futures.Future usage above

Araneidae commented 1 week ago

This issue is exasperating, because it arises from a combination of two mistakes:

  1. It looks as if adding a "truthiness" test to ca_nothing was a mistake. Certainly this test is not necessary as all CA values returned by cothread support the .ok attribute.
  2. Bluntly, the tests in concurrent.futures._base are wrong, and should have been written as if self._exception is not None. However, this appears to be established practice so we have to adapt our libraries accordingly.

I have raised https://github.com/DiamondLightSource/cothread/issues/67 against https://github.com/DiamondLightSource/cothread