Dict with `=` support similar to f-str `=`


Please see the below snippet:

some_thing = 5
another_thing = 6

gets_unpacked_into_kwargs = {
    "some_thing": some_thing,
    "another_thing": another_thing


In the above code, we see the author desires a 1-1 correspondence of the some_func’s kwarg names with variable names, so later dict unpacking can be directly applied. The kwarg names have been duplicated to be the dict keys.

I think this is somewhat common in facade interfaces and wrapper functions.


Python 3.8 introduced the = specifier to f-strings for debugging (docs link).

I think it could be interesting if dict supported something similar:

some_thing = 5
another_thing = 6

gets_unpacked_into_kwargs = {

# {'some_thing': 5, 'another_thing': 6}

This would enable:

  • DRY facade/wrappers, because it decreases the retyping of names to enable dict unpacking downstream
  • Remove a degree of freedom from the facade/wrapper, as now the 1-1 correspondence has one less indirection (retyping kwarg names as dict keys)

Cheers to Python!

1 Like

See previous discussion: Shorthand notation of dict literal and function call


Oh dang, I made a duplicate! I will read through the other thread, and anything valuable from this not mentioned there, I will post.

Thank you!