You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inconsistent TypeError messages with callables #136327
If this is recognized as unwanted behaviour, I'm ready to make a PR.
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Edit: ** also does not work properly:
# the code from the first example>>>A()(**1)
Traceback (mostrecentcalllast):
File"<python-input-26>", line1, in<module>A()(**1)
~~~^^^^^TypeError: somerandomtextargumentafter**mustbeamapping, notint
I've done some investigation on this bug. Seems that it's harder, than I initially thought.
The function's name is received via _PyObject_FunctionStr, which indeed gets the function's qualname. If the qualname isn't present, it just gets whatever is in __str__/__repr__ of the function.
Regarding the examples I've shown earlier:
Example with exit is behaving this way, because some objects in __builtins__ for some reason do not have the __qualname__ attribute. Here's the full list:
I'm not quite sure about the dunder ones, but all others definetly should have a qualname.
The example with the class, on the other hand works that way, because the constructed object is passed as a function into _PyObject_FunctionStr. Since it does not have a __qualname__, it defaults to whatever is in __str__/__repr__ of that object. Possible solution would be to just add an edge-case handler to _PyObject_FunctionStr: if an object is not an instance of function or builtin_function_or_method, then we try searching in object.__call__.
Activity
pythongh-136327: Harmonize arg types for incompatibel types after `*`…
sobolevn commentedon Jul 6, 2025
Please, go ahead :)
I would love to review it!
Tapeline commentedon Jul 7, 2025
I've done some investigation on this bug. Seems that it's harder, than I initially thought.
The function's name is received via
_PyObject_FunctionStr, which indeed gets the function's qualname. If the qualname isn't present, it just gets whatever is in__str__/__repr__of the function.Regarding the examples I've shown earlier:
exitis behaving this way, because some objects in__builtins__for some reason do not have the__qualname__attribute. Here's the full list:I'm not quite sure about the dunder ones, but all others definetly should have a qualname.
_PyObject_FunctionStr. Since it does not have a__qualname__, it defaults to whatever is in__str__/__repr__of that object. Possible solution would be to just add an edge-case handler to_PyObject_FunctionStr: if an object is not an instance offunctionorbuiltin_function_or_method, then we try searching inobject.__call__.Merge branch 'refs/heads/main' into fix-pythongh-136327
gh-136327: Fix inconsistent ``TypeError`` messages regarding invalid …
pythongh-136327: Fix inconsistent ``TypeError`` messages regarding in…