You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered the following behaviour while (foolishly) trying to monkeypatch a HasStrictTraits subclass. The fact that the monkeypatching doesn't work isn't really surprising. What is suprising is that the attempt to monkeypatch one instance of the class breaks the class itself.
>>> from traits.api import *
>>> class A(HasStrictTraits):
... def start(self): print "Starting"
...
>>> try:
... A().start = 3.2 # Monkey-patching fails; too bad.
... except Exception:
... pass
...
>>> A().start # Surprise: the failure above affects new A instances!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute 'start'
What appears to be happening is that the assignment to A().start creates a new class trait start for A and puts it into the A.__class_traits__ dictionary, before the failure occurs. After the failure, that new class trait still exists.
The text was updated successfully, but these errors were encountered:
It looks like get_prefix_trait in ctraits.c could be the place to fix this. I don't have time to produce a fix right now; I may come back to this later.
I encountered the following behaviour while (foolishly) trying to monkeypatch a
HasStrictTraits
subclass. The fact that the monkeypatching doesn't work isn't really surprising. What is suprising is that the attempt to monkeypatch one instance of the class breaks the class itself.What appears to be happening is that the assignment to
A().start
creates a new class traitstart
forA
and puts it into theA.__class_traits__
dictionary, before the failure occurs. After the failure, that new class trait still exists.The text was updated successfully, but these errors were encountered: