Indexing with keyword arguments

pip install kwkey==0.0.2


PEP 472 -- Support for indexing with keyword arguments

This package provides experimental support for indexing with keyword argments, as proposed in

We can write

    fn(1, 2, a=3, b=4)

and some users wish to be able to write

    d[1, 2, a=3, b=4]

particularly for use in data science and annotations.

The module provide a helper function

    from kwkeys import o

such that

   d[o(1, 2, a=3, b=4)]

works as well as can be reasonably expected, or so the author thinks.

In module kwkey/ there's an implementation of a class PointMap. It is a subclass of dict which supports namedtuple style access to keys.

My approach uses a helper class K for implementing these experiments. Some wish for the syntax of Python to be extended, to allow keyword arguments in the d[...] syntax.

If the syntax is extended, I believe a helper class such as K would be a good idea. Steven D'Aprano believe that K is irrelevant, except for experimentation.

This package, once refined and production ready, could be used to allow the the style of the new syntax to be used with current Python, via

   d[o(1, 2, a=3, b=4)]

instead of

    d[1, 2, a=3, b=4]

For a recent discussion of PEP 472, see

To test installation, do

$ python3 -m kwkey.test
kwkey.jfine TestResults(failed=0, attempted=0)
kwkey.example_jfine TestResults(failed=0, attempted=7) TestResults(failed=0, attempted=0)
kwkey.test TestResults(failed=0, attempted=0)
kwkey.test_K TestResults(failed=0, attempted=8)
kwkey.sdaprano TestResults(failed=0, attempted=0)

and check for no failures. (The number of tests will change over time.)