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

change label type to string #261

Closed
dave-doty opened this issue Jul 18, 2023 · 1 comment
Closed

change label type to string #261

dave-doty opened this issue Jul 18, 2023 · 1 comment
Assignees
Labels
closed in dev invalid This doesn't seem right

Comments

@dave-doty
Copy link
Member

dave-doty commented Jul 18, 2023

Scadnano supports the notion of a label attached to a strand, domain, loopout, or extension.

Currently, the type of label is an arbitrary JSON-serializable object. However, this makes type checking awkward, and since such objects can be mutable, the web interface (which relies on immutable state date) might have unforeseen problems due to this.

It would be simpler to simply say the type of label is a string. If a user wants more structured data, they can do the JSON serialization and deserialization themselves. Note that this will be a breaking change.

See UC-Davis-molecular-computing/scadnano#878

@dave-doty dave-doty added the invalid This doesn't seem right label Jul 18, 2023
@dave-doty dave-doty self-assigned this Jul 18, 2023
dave-doty added a commit that referenced this issue Jul 18, 2023
…label-type-to-string

closes #261: change `label` type to `str`
@dave-doty
Copy link
Member Author

dave-doty commented Jul 18, 2023

Release notes

Breaking change: labels must be strings

Changed the type of label field in Strand, Domain, Loopout, and Extension to str instead of an arbitrary object.

This is a breaking change because existing code using non-string labels will have to be altered to change the data to a string before storing and change it back to structured data when reading.

Users can serialize to a string and deserialize back to structured data manually using the json package.

Before, this was possible:

from typing import List

# previously was possible, now is not supported
nums = [1, 2, 3]
strand.label = nums   # stores strand.label as the list [1, 2, 3]; would be a mypy type error now

# and to get the structured data back out:
nums: List[int] = strand.label  # would be a mypy type error now

Now this is necessary to store a list of int's in the label:

import json
from typing import List

nums = [1, 2, 3]
strand.label = json.dumps(nums)  # stores strand.label as the string '[1, 2, 3]'

# and to get the structured data back out:
nums: List[int] = json.loads(strand.label)  # nums is now the list [1, 2, 3]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed in dev invalid This doesn't seem right
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant