DiamondLightSource / DiamondLightSource/cothread
Testing `ca_nothing` for boolean needs to be deprecated
- Dominant language
- C
- Stars
- 13
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
As discussed in https://github.com/dls-controls/aioca/issues/45 it would appear that allowing a `ca_nothing` value to return `False` to a boolean test triggers unexpected behaviour: it turns out that `Exception` subclasses are expected by core Python libraries to return `True` when tested with `__bool__`.
The obvious fix is to delete the implementation of `ca_nothing.__bool__` here: https://github.com/DiamondLightSource/cothread/blob/bb6245082c22069abea0fa5f00f710777d632cda/src/cothread/catools.py#L103-L105 but unfortunately this is a breaking change for any code which is testing `bool(value)` rather than `value.ok`. The only reasonable solution is probably to raise a one-shot deprecation warning when this function is called.
Fortunately I don't think the boolean test feature of `ca_nothing` is documented, but this still needs to be flagged as a breaking change.
Contributor guide
Assessment
This issue has not been assessed yet.