Message369421
While trying to write tests, I stumbled across something interesting: _PyObject_FunctionString as discussed here ( https://bugs.python.org/issue37645 ) returns a string that also includes the module name where applicable. For example, the module name is included behind the qualname in the following situation:
>>> from random import Random
>>> Random.seed(a=1, **{"a":2})
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
Random.seed(a=1, **{"a":2})
TypeError: random.Random.seed() got multiple values for keyword argument 'a'
or:
>>> class A:
... def foo(bar):
... pass
...
>>> A().foo(bar=1, **{"bar":2})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __main__.A.foo() got multiple values for keyword argument 'bar'
From what I can tell, this seems to happen mostly during the CALL_FUNCTION_EX instruction (unpacking *args and **kwargs), while we don't get this level of qualification during the actual do_call_core. Maybe _PyObject_FunctionString should ideally be used everywhere applicable, but there seems to be a different issue with that: the _PyEval_EvalCode function where the error handling occurs doesn't receive a reference to the function, only references to the function's code object and qualname (unless I'm missing to something).
Should the signature of _PyEval_EvalCode be modified? Or should we be satisfied with the half-measure of including the qualname but not the module (at least for now)? Is there a good reason for the different qualifiers for functions when encountering different types of invalid arguments?
There's also a block that I couldn't figure out how to reach in tests from Python code: at https://github.com/python/cpython/blob/master/Python/ceval.c#L4233 ("keywords must be strings" when passing as two arrays), I don't know how to reach this code in a way that isn't a SyntaxError first. |
|
Date |
User |
Action |
Args |
2020-05-20 07:09:01 | Dennis Sweeney | set | recipients:
+ Dennis Sweeney, chris.jerdonek, xtreak |
2020-05-20 07:09:01 | Dennis Sweeney | set | messageid: <1589958541.62.0.734803330361.issue40679@roundup.psfhosted.org> |
2020-05-20 07:09:01 | Dennis Sweeney | link | issue40679 messages |
2020-05-20 07:09:01 | Dennis Sweeney | create | |
|