traits icon indicating copy to clipboard operation
traits copied to clipboard

Add support to exclude internal traits from being reported

Open kitchoi opened this issue 4 years ago • 2 comments

Currently trait_added and trait_modified are reported by public methods HasTraits.traits and HasTraits.class_traits. Both of these traits are defined by traits for internal use and are typically not useful for downstream projects.

Since there are no other ways to exclude these two internal traits, when projects try to get a list of traits for their classes, they are typically filtered by hard-coding, like this:

traits = instance.class_traits()
traits.pop("trait_added") 
traits.pop("trait_modified") 

This makes it difficult to add more internal traits (e.g. for solving #1047) without breaking user code.

Possible solution is to add a specific metadata on these internal traits such that there is a documented and supported way to exclude them via the public interface. In addition to this, maybe a helper method that does this filter by default, similar to editable_traits and visible_traits, would be useful.

kitchoi avatar May 18 '20 16:05 kitchoi

Related: #1097

mdickinson avatar May 18 '20 16:05 mdickinson

The "_items" traits added for supporting listening to mutations of List/Dict/Set using on_trait_change may be considered internal traits as well.

kitchoi avatar Nov 06 '20 13:11 kitchoi