I am trying to create a custom trait which represents a unipath.Path object. It seems advantageous to re-use the machinery provided by the File trait, so my thought was to use multiple inheritance.
from unipath import Path
from traits import File
class PathTrait(Path,File):
    pass
class A(HasTraits):
    p = PathTrait()
However, when i used this via  A(p='/tmp/'), A.p does not have any methods associated with the Path object, as i would expect. Should i be implementing get and set methods?
                        
What do you expect
A(p='/tmp')should do?I can tell what you are trying to do but this statement should fail with
TypeErrorif your code was correct. Instead of type error, you are replacing the variable P on theAobject, which was previously an instance ofPathTrait, with a string.What you're trying to do is conceptually mixed up.
Fileis a class which represents a trait object. Technically python allows you to extend this object, because python has very little type safety, but it doesn't mean your python class will now suddenly act like a trait.To define custom traits you will need to use tools designed to operate with traits such as the
Traitconstructor.