`Snapshot` and `SnapshotDict` makes for a confusing API
Describe the bug
Basically, a Snapshot can be updated, a SnapshotDict cannot. Interacting with a Snapshot is hard (basically a bunch of PMaps. Interacting with SnapshotDict is somewhat easier, but you still need to use a lot of .items() and .values() and so on.
Expected behavior
Both the consumer and the evaluator needs to keep track of state in a Snapshot, so maybe this should be the primary class to represent the snapshot, but then it needs to be easier to interact with.
If a SnapshotDict became as able as the Snapshot, maybe it could be the primary representation, but then maybe the use of pydantic needs to be deprecated, since the GUI struggles with it? And we don't really use any of the pydantic API, so perhaps it was a premature optimization?
@mortalisk and @sondreso are probably opinionated, so ping.
I'm thinking pydantic is not an end all, be all for data representation. And then one can either look at using it in this case as an premature optimisation, or as a fast-track to early structuring of data until one figures out what one really needs 🤷🏻
I'm thinking pydantic is not an end all, be all for data representation. And then one can either look at using it in this case as an premature optimisation, or as a fast-track to early structuring of data until one figures out what one really needs 🤷🏻
In that case, typing.NamedTuple would probably be a much better fit. It probably exactly equivalent when your pydantic model looks like this:
class Foo(BaseModel):
name: str
Except it is probably a bagillion times more performant (which somewhat matters for these structures).
I completely agree! Or potentially a data class when we leave 3.6 behind...
The snapshot as it currently works should be viewed as a easy in-memory multi version concurrency control DB, not as a complicated way to do random access memory. Whether we actually need that, is of course an important discussion to also have. In either case, we should strive to make it as easy as possible to work with, but remember that some simplifications can't be made without loosing some potential advantages, like serialize in one thread, while doing updates in another, rollback, etc.
As for pydantic, I guess for us it is just a schema for the snapshot and update structure, and a DSL for making that structure. I think it also has some possibility of generating documentation for the format of the dict. Any solution that can achieve the same is good.