Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font default validation not working correctly on subclasses #945

Closed
corranwebster opened this issue May 16, 2022 · 4 comments
Closed

Font default validation not working correctly on subclasses #945

corranwebster opened this issue May 16, 2022 · 4 comments

Comments

@corranwebster
Copy link
Contributor

corranwebster commented May 16, 2022

In the following code, b.f is undefined when assigned at the class level, but works fine when assigned as ab attribute (so not a problem with the font):

In [1]: from enable.trait_defs.api import KivaFont
In [2]: from traits.api import HasTraits
In [3]: class A(HasTraits):
   ...:     f = KivaFont()
   ...: 
In [4]: class B(A):
   ...:     f = "modern 11"
   ...: 
In [5]: b = B()
In [6]: b.f
Out[6]: <undefined>
In [7]: b.f = "modern 11"
In [8]: b.f
Out[8]: Font(face_name='', size=11, family=3, weight=400, style=0, underline=False, encoding=0)

This might be a traits bug?

@mdickinson
Copy link
Member

mdickinson commented May 19, 2022

Do we have existing code that uses this pattern? The general form of this pattern hasn't worked in Traits for quite a while. As a workaround, can we recommend that people not subclass in this way, and instead do:

class A(HasTraits):
    f = KivaFont()
    
class B(A):
    f = KivaFont("modern 11")

We should of course fix this in Traits eventually, but I'm having trouble seeing this as something that needs an urgent fix in Traits when this aspect of Traits hasn't changed for quite a while.

@mdickinson
Copy link
Member

Alternatively, could KivaFont override the parts of TraitType necessary to make this pattern work specifically for that class?

@corranwebster
Copy link
Contributor Author

corranwebster commented May 20, 2022

The problem is that the breakage is in HasTraits/CTrait which we can't override. This is because we are overriding clone already to correctly provide a callable_with_args default, but HasTraits doesn't handle that correctly.

@corranwebster
Copy link
Contributor Author

This is fixed by enthought/traits#1645 which is available in Traits >= 6.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants