[Python-ideas] Provide additional debug info for OSError and WindowsError

2019-04-12 Thread Giampaolo Rodola'
When dealing with C extensions from Python there are circumstances where a function is called and we get an OSError(errno) exception without knowing what exactly went wrong internally. This is especially not obvious on Windows, where multiple MSDN APIs may be invoked within the same C function and

[Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Viktor Roytman
Currently, unpacking a dict in order to pass its items as keyword arguments to a function will fail if there are keys present in the dict that are invalid keyword arguments: >>> def func(*, a): ... pass ... >>> func(**{'a': 1, 'b': 2}) Traceback (most recent call last):

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Bruce Leban
On Fri, Apr 12, 2019, 8:12 AM Viktor Roytman > >>> func(**{'a': 1, 'b': 2}) > Traceback (most recent call last): > File "", line 1, in > TypeError: func() got an unexpected keyword argument 'b' > Perhaps func(***kws)? I think this is a real problem given the frequent conventio

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Chris Angelico
On Sat, Apr 13, 2019 at 1:12 AM Viktor Roytman wrote: > > Currently, unpacking a dict in order to pass its items as keyword arguments > to a function will fail if there are keys present in the dict that are > invalid keyword arguments: > > >>> def func(*, a): > ... pass > ... >

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Viktor Roytman
I could see this being an option, but to someone unfamiliar with it, it might seem strange that * unpacks iterables, ** unpacks dicts, and *** is a special thing only for keyword arguments that mostly behaves like **. On Friday, April 12, 2019 at 11:26:37 AM UTC-4, Bruce Leban wrote: > > > On Fr

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Viktor Roytman
That is certainly an option for functions that you have defined for yourself, but generally not an option for a function from a library. I am interested in a solution that works in general. On Friday, April 12, 2019 at 11:48:38 AM UTC-4, Chris Angelico wrote: > > On Sat, Apr 13, 2019 at 1:12 AM

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Lucas Bourneuf
Hello ! I made *fief*, a small python package allowing just that using a decorator: from fief import filter_effective_parameters as fief @fief def func(a, b): # some implementation # and then, use it as you want to: func(**MY_BIG_CONFIG_DICT_WITH_MANY_WEIRD_KEYS) Th

Re: [Python-ideas] Provide additional debug info for OSError and WindowsError

2019-04-12 Thread eryk sun
On 4/12/19, Giampaolo Rodola' wrote: > > As such I was thinking that perhaps it would be nice to provide 2 new > cPython APIs: > > PyErr_SetFromErrnoWithMsg(PyObject *type, const char *msg) > PyErr_SetFromWindowsErrWithMsg(int ierr, const char *msg) > PyErr_SetExcFromWindowsErrWithMsg(PyObject *ty

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Rhodri James
On 12/04/2019 16:10, Viktor Roytman wrote: Currently, unpacking a dict in order to pass its items as keyword arguments to a function will fail if there are keys present in the dict that are invalid keyword arguments: >>> def func(*, a): ... pass ... >>> func(**{'a': 1, 'b

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Viktor Roytman
Any time I am using a function from a library that accepts keyword arguments. For example, an ORM model constructor that accepts fields as keyword arguments (like Django). On Friday, April 12, 2019 at 12:57:43 PM UTC-4, Rhodri James wrote: > > On 12/04/2019 16:10, Viktor Roytman wrote: > > Curr

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Viktor Roytman
That is an interesting solution. In the case of a function from another library, you could apply the decorator as needed like. fief(func)(**{'a': 1, 'b': 2}) It looks a little strange, but I've seen stranger. On Friday, April 12, 2019 at 12:18:34 PM UTC-4, Lucas Bourneuf wrote: > > Hello !

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Eric V. Smith
Viktor is looking for something at the call site, not the function definition site (which he might not control). I wrote calllib (horrible name, I know). It can do this, although I just noticed it needs updating for keyword-only params. But, here it is without keyword-only params: >>> from c

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Rhodri James
Re-ordered to avoid top-posting... On 12/04/2019 18:50, Viktor Roytman wrote: On Friday, April 12, 2019 at 12:57:43 PM UTC-4, Rhodri James wrote: On 12/04/2019 16:10, Viktor Roytman wrote: Currently, unpacking a dict in order to pass its items as keyword arguments to a function will fail if

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Viktor Roytman
> > > Any time I am using a function from a library that accepts keyword > > arguments. For example, an ORM model constructor that accepts fields as > > keyword arguments (like Django). > > That's not the same issue at all, if I'm understanding you correctly. > In any case, surely you need to

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Nathaniel Smith
I don't think it's possible to make this work reliably. In particular, it's an important feature of python that you can make wrappers that pass through arguments and are equivalent to the original function: def original(a=0): ... def wrapper(*args, **kwargs): return original(*args, **kwar

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Eric V. Smith
On 4/12/2019 11:29 AM, Rhodri James wrote: On 12/04/2019 16:10, Viktor Roytman wrote: Currently, unpacking a dict in order to pass its items as keyword arguments to a function will fail if there are keys present in the dict that are invalid keyword arguments: >>> def func(*, a): ... 

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Eric V. Smith
On 4/12/2019 1:52 PM, Viktor Roytman wrote: That is an interesting solution. In the case of a function from another library, you could apply the decorator as needed like.     fief(func)(**{'a': 1, 'b': 2}) It looks a little strange, but I've seen stranger. Indeed. That's not so bad, and I'l

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Anders Hovmöller
> On 12 Apr 2019, at 19:16, Eric V. Smith wrote: > > I don't want to speak for the OP, but I have a similar use case (which is why > I wrote calllib). My use case is: I have number of callables that I don't > control. I also have a dict of parameters that the callables might take as > param

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Eric V. Smith
On 4/12/2019 4:00 PM, Anders Hovmöller wrote: On 12 Apr 2019, at 19:16, Eric V. Smith wrote: I don't want to speak for the OP, but I have a similar use case (which is why I wrote calllib). My use case is: I have number of callables that I don't control. I also have a dict of parameters tha

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Viktor Roytman
> > That seems to me to be quite different issue. Just throwing invalid stuff > on the ground in this scenario will avoid a crash but lose data. This seems > much worse to me than the crash. > Throwing it away does seem extreme. Maybe something that indicates what's left over? In other words

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Greg Ewing
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. R

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Amber Yust
I'm not a fan of this idea for two (related) reasons: 1) This seems like something that's a relatively niche case to *want* to do rather than doing unintentionally. 2) This vastly increases the chance of silent bugs in code. With regards to #1, the main examples I've seen posited in this thread a