DiamondLightSource / DiamondLightSource/fastcs
Add support for `int` as type when creating Attributes and no metadata is required
- Dominant language
- Python
- Stars
- 6
- Forks
- 8
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 3
Description
Often when introspecting devices they will return the type as a string, so it would be convenient to be able to pass this straight into Attributes rather than having to map them to the FastCS types.
Add a `_parse_datatype` function with a match statement mapping the builtin types to fastcs types, call it in `Attribute.__init__` when storing the datatype, ~~make a TypeVar `DataTypeStr` `Literal["bool", "int", ...]` matching the `T` typevar in datatypes.py,~~ change parameter type to ~~`DataType[T] | T | DataTypeStr`~~ `DataType[T] | T` in all attribute `__init__` methods.
Edit: "int" is not required. My idea was this would be useful when converting serialised representations of parameters into Attributes, but the driver should be using pydantic to convert this to a structure anyway and not passing the values directly from the serialised form.
This should also allow us to not need to wrap enum.Enum with FastCS.Enum.
## Acceptance Criteria
- `AttrR(int, ...)` are equivalent to `AttrR(Int(), ...)`
- And other types
Contributor guide
Research direction
Start with datatypes.py and the Attribute.__init__ methods mentioned in the issue, then trace AttrR and Int to understand the existing datatype representations. Implement the requested builtin-type mapping and verify the acceptance criteria: AttrR(int, ...) should match AttrR(Int(), ...), with equivalent behavior for the other supported types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100