Syntactic sugar to encourage use of named arguments

I found @ntessore’s example above helpful for comparing the =x vs x=, so here they are mapped into all 5 options (and the status quo), with one positional and one explicit kwarg and 3 implicit kwargs:

Status quo

cbar = fig.colorbar(
    img,
    ax=my_axis,
    location=location,
    fraction=fraction,
    pad=pad,
)

f(x=)

cbar = fig.colorbar(
    img,
    ax=my_axis,
    location=,
    fraction=,
    pad=,
)

f(=x)

cbar = fig.colorbar(
    img,
    ax=my_axis,
    =location,
    =fraction,
    =pad,
)

f(%x)

cbar = fig.colorbar(
    img,
    ax=my_axis,
    %location,
    %fraction,
    %pad,
)

f(*, x)

cbar = fig.colorbar(
    img,
    ax=my_axis,
    *,
    location,
    fraction,
    pad,
)

f(pass x)

cbar = fig.colorbar(
    img,
    ax=my_axis,
    pass location,
    pass fraction,
    pass pad,
)

Edit: I am assuming here that the prevalent style, if not the required syntax, would be for implicit kwargs to come after any explicit kwargs.

7 Likes