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

ReadOnly with an explicit value_type #1609

Closed
mpenning opened this issue Dec 27, 2021 · 2 comments
Closed

ReadOnly with an explicit value_type #1609

mpenning opened this issue Dec 27, 2021 · 2 comments

Comments

@mpenning
Copy link

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?

@mdickinson
Copy link
Member

I'm afraid there isn't, at the moment. There's a PR open along those lines, though: #488. Would the feature described in that PR work for you, or were you looking for something different?

@mdickinson
Copy link
Member

Converting to a discussion.

@enthought enthought locked and limited conversation to collaborators Aug 10, 2022
@mdickinson mdickinson converted this issue into discussion #1705 Aug 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants