Skip to content

Testing ca_nothing for boolean needs to be deprecated #67

Open

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.

Activity

  1. Araneidae commented on Jul 9, 2024

    @Araneidae
    CollaboratorAuthor

    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.

    Unfortunately not only is this documented behaviour, it is recommended:

    set. The return code can be tested for boolean success, so for example it
    is possible to write::
    if not caput(pv, value, throw=False):
    # process caput error

  2. Araneidae commented on Dec 2, 2024

    @Araneidae
    CollaboratorAuthor

    The patch described in DiamondLightSource/aioca#45 (comment) should probably be applied to cothread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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