ref(grouping): Simplify handling of variant name and exception data #97458
+31
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During grouping, we pass data from one component strategy to another by storing it in the grouping context. In that context, two values - the variant name and a blob of exception data - are only sometimes defined. Until recently, the
GroupingContext
class supported key-lookup using subscript notation (context[some_key]
) the same way a dictionary would, but lacked the safer.get()
method. We therefore currently initialize both values toNone
, to prevent raising aKeyError
if the values haven't been set.Now that
.get()
has been implemented, though, we don't need to do that. This PR therefore switches the way we access them to use.get()
, and removes the default initialization. In order to enforce whenvariant_name
is or isn't expected to be defined, it also extends the practice already followed in some strategies of asserting on its existence (or lack thereof). This ensures that if we ever make changes to the grouping code, we'll know right away if our assumptions have been violated.