enthought / enthought/traits

Error from equality check are swallowed when filtering for trait change events

Open
#1,230 5 comments 0 reactions 0 assignees View on GitHub
type: discussion
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

The existing behaviour for `on_trait_change` (and `observe`) is that if equality check fails, the error will be swallowed and the change handler is fired. This issue is about whether we should do something else with the exception instead of or in addition to swallowing it.

Currently the relevant code is here, but that is being moved by #1165:
https://github.com/enthought/traits/blob/aa6353148570cf4aa49144d7e147529874a3e2d6/traits/ctraits.c#L2366-L2370

Here is the existing behaviour (nothing fails, and nothing is logged):
```
from traits.api import *

class NotComparable:

def __eq__(self):
raise RuntimeError("Sorry!")

class Foo(HasTraits):
dummy = Any()

def handler(_):
print("changed")

foo = Foo()
foo.on_trait_change(handler, "dummy")
foo.dummy = NotComparable() # print 'changed'
foo.dummy = NotComparable() # print 'changed'

foo = Foo()
foo.observe(handler, "dummy")
foo.dummy = NotComparable() # print 'changed'
foo.dummy = NotComparable() # print 'changed'
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.