Skip to content

Testing ca_nothing for boolean needs to be deprecated #67

@Araneidae

Description

@Araneidae

As discussed in DiamondLightSource/aioca#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:

def __bool__(self):
return self.ok
__nonzero__ = __bool__ # For python 2
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions