Bruce Leban wrote:
I think this is a real problem given the frequent convention that you can freely add fields to json objects with the additional fields to be ignored.

Unpacking json objects isn't something one does every day, so I
don't think it would be worth adding syntax just for this.

Rather than new syntax, how about a helper function such as:

def call_with_kwds_from(func, kwds):
    code = func.__code__
    names = code.co_varnames[:code.co_argcount]
    func(**{name : kwds[name] for name in names})

Usage example:

def f(a, b):
    print("a =", a, "b =", b)

d = {"a": "a_value", "b": "b_value", "c": "something extra"}

call_with_kwds_from(f, d)

--
Greg
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to