Properly Handle Duplicate Kwargs
See original GitHub issuedef print_kwargs(**kwargs):
print(kwargs)
print_kwargs(**{'a': 'a', 'a': 'b'})
This works in python, but not when compiled with Cython. I think it might have something to do with the way kwargs are unpacked.
It’s good to point out that this is illegal in python, and will raise a SyntaxError(keyword argument repeated):
print_kwargs(a='a', a='b')
Also worth pointing out that, Interestingly enough, this works the same in python as in cython:
print({'a': 'a', 'a': 'b'})
printing {'a': 'b'}
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Managing duplicate keyword arguments - python
Managing duplicate keyword arguments · 1. 1. You'll know that if e.g. local_a is already set. 2. You aren't currently doing that at...
Read more >PEP 692 – Using TypedDict for more precise **kwargs typing
A TypedDict that is used to type **kwargs could potentially contain keys that are already defined in the function's signature. If the duplicate...
Read more >Understanding *args and *kwargs arguments in Python
An important point worth mentioning here is that the names args and kwargs are just placeholders and can be replaced with any other...
Read more >The Use and Abuse of Keyword Arguments in Python
When this happens, if you went the **kwargs route, your subclass interface can "stay the same". It's very unhelpful shortcut to take, however....
Read more >Code Style - The Hitchhiker's Guide to Python - Read the Docs
In the function body, kwargs will be a dictionary of all the passed named ... also used at the interactive prompt to hold...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah, yeah. The dictionary and keyword arguments would have probably been processed and consolidated completely by CPython before being passed into the Cythonized bits.
Inlining the function call does produce the broken result:
I wonder if Python is handling the kwargs before calling the the function? Can you inline a call to the function?