Skip to content

Make unit model hashable #186

@tstorek

Description

@tstorek

Is your feature request related to a problem? Please describe.
Currently, the units model is not hashable although the content should be immutable and, hence, frozen.
But due to the missing Config in the model the __hash__ function is not generated by pydantic.

Describe the solution you'd like
I would like to add the following content to the model:

class Unit(BaseModel):
    ...

    class Config:
        extra = 'ignore'
        allow_population_by_field_name = True
        allow_mutation = False
        frozen = True
           

Describe alternatives you've considered
Inherit, the Unit model and add a specific Config object. However, this may lead to inconssitency

Additional context
Use case:
I have a list ob sensors that also contains information about the unit.
For mapping measurements to the sepcific sensors I regularly must loop throuth this list. Therefore, caching such lookup can be wuite useful. Caching though requires hashing of the Objects in the list that I qant to operate on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions