Skip to content

ReadOnly with an explicit value_type #1609

@mpenning

Description

@mpenning

Is there a way to enforce ReadOnly trait type?

For example, I need something like this...

from traits.api import CStr, ReadOnly
from traits.api import HasTraits

class Foo(HasTraits):
    attr_01 = ReadOnly(value_type=CStr)

foo = Foo(attr_01=123)   # <--- This does not result in `CStr` value today...
print("attr_01 Type:", type(foo.attr_01))
print("attr_01 Value:", foo.attr_01)

Running this:

attr_01 Type: <class 'int'>
attr_01 Value: 123

Is there a way to achieve ReadOnly with a value_type today?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions