enthought / enthought/traits

class_traits uses __base_traits__ instead of __class_traits__

Open
#674 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

I came across the following base class and subclass:
```
class Base(HasTraits):
a = Str("a")

class Child(Base):
a = "overridden"
```

If you try to inspect the default value for `Child.a`:
```
> Child.class_traits()["a"].default
"a"
```
But I'd expect "overridden" to be returned instead.

If I access `__class_traits__` instead, I get the value I expected:
```
> Child.__class_traits__["a"].default
"overridden"
```

(It was new to me that redefining the traits in a subclass is considered as redefining the traits with a new default value. See this [branch](https://github.com/enthought/traits/blob/ba7c10fa28666219e276c7eeeac7e3e7168a45c2/traits/has_traits.py#L620).)

Turns out `HasTraits.class_traits` is using `__base_traits__`, not `__class_traits__`:
https://github.com/enthought/traits/blob/ba7c10fa28666219e276c7eeeac7e3e7168a45c2/traits/has_traits.py#L3085-L3094

Is this intended? Or is this a bug?

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.