I’ve read through the discussion on the ticket and I have an argument for the change that was not brought up, however, in closing the ticket picnixz asked that any further discussion originate here.
I have a need to transform a data structure and I’ve used a comprehension. The new object selects values from either a list of dicts (new_values), a list of objects (old_values) or not at all if they key is missing from both. Which list is sourced will vary from key to key. The value section of the comprehension therefore needs to be the same. I tried to use partial to normalize the getter, as when a key’s value will be derived from a dict, I need a default for get (I specifically need False, not the falsey None). The objects are instances of an adapter class to an external system that guarantees a boolean attribute for any name.
[
{inner_k: v(inner_k) for inner_k in inner_keys}
for outer_k in outer_keys
if (
v := partial(new_values[outer_k].get, default=False)
if outer_k in new_values else
outer_k in old_values and old_values[outer_k].__getattr__
)
]
A convoluted circumstance, but the moral of the story is, default as a positional-only second argument renders dict.get() unusable with partial if you need a default. Perhaps others can think of a simpler example of a use of partial with dict.get().
The following solution works fine, but I can get pedantic and the partial approach not working when is seems like it should was a sliver in my mind
[
{inner_k: v(inner_k) or False for inner_k in inner_keys}
for outer_k in outer_keys
if (
v := new_values[outer_k].get
if outer_k in new_values else
outer_k in old_values and old_values[outer_k].__getattr__
)
]
The 1-3% performance hit does give me pause, but that is the only argument I find compelling against the change. The constraint is surprising and as others have pointed out, makes dict not implement collections.abc.Mapping. At the very least, the docs should explain that the positional-only constraint exists for significant performance reasons despite the inconsistencies it creates.