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

general readonly tag #315

Merged
merged 4 commits into from
Sep 27, 2019
Merged

general readonly tag #315

merged 4 commits into from
Sep 27, 2019

Conversation

jmilloy
Copy link
Collaborator

@jmilloy jmilloy commented Sep 27, 2019

Node traits tagged as 'readonly' or as 'attr' can be specified using keyword arguments during Node instatiation, but cannot be later modified. It uses the read_only flag under the hood but is a slightly more flexible.

class MyDataSource(DataSource)
    source = tl.Unicode().tag(readonly=True)
    my_attr = tl.Int().tag(attr=True)
>>> node = MyDataSource(source='mysource', my_attr=8)
>>> node.source = 'other'
...
traitlets.traitlets.TraitError: The "source" trait is read-only.
>>> node.my_attr = 6
traitlets.traitlets.TraitError: The "my_attr" trait is read-only.

…d_only.

 - observe (and tests) for handling source changes in data sources has been removed.
 - the traitlets read_only does not allow setting the trait at initialization, so that is handled in _first_init.
 - note: set_trait still works for read_only traits.
… modified. DataSource source, native_coordinates, and dataset are tagged as readonly, among others. Replaces the cumbersome _first_init proposal.
@jmilloy jmilloy self-assigned this Sep 27, 2019
@jmilloy jmilloy requested a review from mpu-creare September 27, 2019 18:29
@jmilloy
Copy link
Collaborator Author

jmilloy commented Sep 27, 2019

@mpu-creare Try this on for size. Replaces #313.

@jmilloy jmilloy requested a review from mlshapiro September 27, 2019 18:30
@jmilloy jmilloy added the enhancement New feature or request label Sep 27, 2019
@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 90.636% when pulling b343713 on feature/readonly_tag into f0beb50 on develop.

@mpu-creare
Copy link
Contributor

Looks good to me. I made a suggestion for a slightly simpler implementation, but you might have had a reason for what you did.

@jmilloy jmilloy merged commit 2a55a65 into develop Sep 27, 2019
@jmilloy jmilloy deleted the feature/readonly_tag branch September 27, 2019 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants