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
-
During refactoring the use of the generic
AttributeDict
in 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
Executor
interface would currently be typed as such: (omittingstdin_input
for brevity)While the
AttributeDict
could have arbitrary keys/attributes, in practice it only containsstdout
,stderr
andexitcode
. The point of theExecutor
interface 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
AttributeDict
is to have attributes, we could express them strongly usingNamedTuple
/@dataclass
for concrete types orProtocol
for abstract types.Defining
Protocol
s would be the least intrusive change, whereasNamedTuple
would be the most intrusive (due to immutability), with@dataclass
somewhere in the middle.Beta Was this translation helpful? Give feedback.
All reactions