Replace/Augment AttributeDict with strong types #225
maxfischer2781
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
During refactoring the use of the generic
AttributeDictin various places made it needlessly difficult to understand and change the code. My preference and suggestion is to use – not generally but where applicable – the strongly typedNamedTuple,Protocol, or similar instead.This isn't really a single, actionable work item and various places may benefit from or even need
AttributeDict. I would like to discuss and collect uses that we can refactor well.As a practical example, the
Executorinterface would currently be typed as such: (omittingstdin_inputfor brevity)While the
AttributeDictcould have arbitrary keys/attributes, in practice it only containsstdout,stderrandexitcode. The point of theExecutorinterface is that client code does not care about the precise executor, meaning different attributes in the provided results would be ignored either way.The code doesn't make that obvious to either automatic (e.g. an IDE) or manual (e.g. a coder) inspection, though.
Since the point of
AttributeDictis to have attributes, we could express them strongly usingNamedTuple/@dataclassfor concrete types orProtocolfor abstract types.Defining
Protocols would be the least intrusive change, whereasNamedTuplewould be the most intrusive (due to immutability), with@dataclasssomewhere in the middle.Beta Was this translation helpful? Give feedback.
All reactions