-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-37645: add new function _PyObject_FunctionStr() #14890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
2a55a9f
733158d
4c0c877
2e1b44e
fa20556
b2e56da
21aee80
402ec96
0307ce9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,6 +196,17 @@ Object Protocol | |
This function now includes a debug assertion to help ensure that it | ||
does not silently discard an active exception. | ||
|
||
|
||
.. c:function:: PyObject* _PyObject_FunctionStr(PyObject *func) | ||
|
||
Return a user-friendly string representation of the function-like object | ||
*func*. This returns ``func.__qualname__ + "()"`` if there is a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning If you want to return a full qualified name (long but unambiguous), return If you want to return a short name (it is enough in many times), return if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is mainly meant as replacement for |
||
``__qualname__`` attribute and ``str(func)`` otherwise. | ||
Note that there is no check that *func* is actually callable. | ||
|
||
.. versionadded:: 3.9 | ||
|
||
|
||
.. c:function:: PyObject* PyObject_Bytes(PyObject *o) | ||
|
||
.. index:: builtin: bytes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1967,7 +1967,7 @@ def test_methods_in_c(self): | |
# different error messages. | ||
set_add = set.add | ||
|
||
expected_errmsg = "descriptor 'add' of 'set' object needs an argument" | ||
expected_errmsg = "set.add() needs an argument" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I consider this a regression: the message is now too similar to calling the method on an instance, but missing an argument. Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: set.add() takes exactly one argument (0 given)
>>> set.add()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: set.add() needs an argument There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, this is confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can change the error message to anything you like, except that it must contain the string
or whatever (surely, this is better than anything mentioning descriptors). Small rant: the bug is really this:
For a Python method, it would correctly note that 2 arguments are required. This is difficult to fix in CPython since |
||
|
||
with self.assertRaises(TypeError) as cm: | ||
set_add() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add :c:func:`_PyObject_FunctionStr` to get a user-friendly string representation | ||
of a function-like object. |
Uh oh!
There was an error while loading. Please reload this page.