When I dive into this https://github.com/tortoise/tortoise-orm/issues/1583,
the error type KeyError
make me so confuse: while running code snippet defaults={'id':'1','question':''};kwargs={'id':'2'};dict(**defaults,**kwargs)
in ipython, it raises TypeError as below
In [1]: defaults={'id':'1','question':''};kwargs={'id':'2'};dict(**defaults,**kwargs)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[1], line 1
----> 1 defaults={'id':'1','question':''};kwargs={'id':'2'};dict(**defaults,**kwargs)
TypeError: dict() got multiple values for keyword argument 'id'
After a lot of trys, I found the mini code to reproduce:
try:
raise ValueError('foo') # no matter what kind of exception
except:
dict(id=1, **{'id': 2}) # raises: KeyError: 'id'
My Python version is 3.11.8
Cloud any one tell me why it raises KeyError?
1