GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-37645: add new function _PyObject_FunctionStr() by jdemeyer · Pull Request #14890 · python/cpython

Conversation

@jdemeyer

@jdemeyer jdemeyer commented Jul 21, 2019 •
edited by miss-islington
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Additional note: the method_check_args function in Objects/descrobject.c is written in such a way that it applies to all kinds of descriptors. In particular, a future re-implementation of wrapper_descriptor could use that code.

CC @vstinner @encukou

https://bugs.python.org/issue37645

Automerge-Triggered-By: @encukou

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jul 21, 2019
@bedevere-bot bedevere-bot added the awaiting review label Jul 21, 2019
ZackerySpytz
ZackerySpytz reviewed Jul 29, 2019
View reviewed changes
Comment thread Objects/object.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Jul 29, 2019

Copy link
Copy Markdown
Member

I would prefer to make it private at the beginning: replace Py with _Py.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jdemeyer

jdemeyer commented Aug 4, 2019

Copy link
Copy Markdown
Contributor Author

I would prefer to make it private at the beginning: replace Py with _Py.

Done.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jdemeyer jdemeyer changed the title bpo-37645: add new function PyObject_FunctionStr() bpo-37645: add new function _PyObject_FunctionStr() Aug 4, 2019
vstinner
vstinner reviewed Aug 12, 2019
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @serhiy-storchaka

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Objects/object.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/object.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/object.rst Outdated

@vstinner vstinner Aug 12, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the qualified name for type(func)?

Would it be possible to also add the module, except for builtin functions?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jdemeyer jdemeyer Aug 18, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the qualified name for type(func)?

I decided to use str(func) as fallback, which looks more useful than f"{type(func)} object".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jdemeyer

jdemeyer commented Aug 13, 2019 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Before changing this PR, could you reply on my last comment on bpo-37645? It might be a better solution to just use str(func) in the error message and then changing some __str__ implementations.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jdemeyer and others added 4 commits August 18, 2019 18:18
@jdemeyer
bpo-37645: add new function PyObject_FunctionStr()
2a55a9f
@jdemeyer
bpo-37645: clear exception in check_args_iterable()
733158d
@jdemeyer
bpo-37645: rename PyObject_FunctionStr() -> _PyObject_FunctionStr()
4c0c877
@jdemeyer
bpo-37645: use str(func) as fallback in _PyObject_FunctionStr()
2e1b44e
@jdemeyer
jdemeyer force-pushed the funcstr branch from ab65a48 to 2e1b44e Compare August 18, 2019 18:16
encukou
encukou reviewed Sep 11, 2019
View reviewed changes
Comment thread Objects/object.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/object.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/ceval.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_descr.py Outdated
set_add = set.add

expected_errmsg = "descriptor 'add' of 'set' object needs an argument"
expected_errmsg = "set.add() needs an argument"

@encukou encukou Sep 11, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@serhiy-storchaka serhiy-storchaka Sep 13, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this is confusing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jdemeyer jdemeyer Sep 13, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The 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 set.add (the function name). So it could be

TypeError: unbound method set.add() needs an argument

or whatever (surely, this is better than anything mentioning descriptors).


Small rant: the bug is really this:

>>> set().add()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: add() takes exactly one argument (0 given)

For a Python method, it would correctly note that 2 arguments are required. This is difficult to fix in CPython since builtin_function_or_method doesn't really know whether it's a function or method. This was one of the things that the rejected PEP 580 would have addressed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
serhiy-storchaka
serhiy-storchaka reviewed Sep 13, 2019
View reviewed changes
Comment thread Doc/c-api/object.rst Outdated
.. 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

@serhiy-storchaka serhiy-storchaka Sep 13, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning __qualname__ without module is not particularly useful.

If you want to return a full qualified name (long but unambiguous), return __module__ + '.' + __qualname__. __module__ can be omitted if it is 'builtins'.

If you want to return a short name (it is enough in many times), return __name__.

if __qualname__ is not available, you can use __name__ instead.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jdemeyer jdemeyer Sep 13, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if __qualname__ is not available, you can use __name__ instead.

This is mainly meant as replacement for PyEval_GetFuncName and all classes supported by that function implement __qualname__. So I see little reason for the additional complexity of supporting __name__.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Doc/c-api/object.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_descr.py Outdated
set_add = set.add

expected_errmsg = "descriptor 'add' of 'set' object needs an argument"
expected_errmsg = "set.add() needs an argument"

@serhiy-storchaka serhiy-storchaka Sep 13, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this is confusing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Objects/object.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jdemeyer
bpo-37645: review fixes
fa20556
@jdemeyer

jdemeyer commented Sep 13, 2019

Copy link
Copy Markdown
Contributor Author

I tried to address all comments.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou
encukou reviewed Oct 8, 2019
View reviewed changes
Comment thread Objects/object.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Oct 8, 2019

Copy link
Copy Markdown
Member

One more nitpick above. Otherwise, this does look like an improvement in the error messages – not only in custom extension callables!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou added 2 commits October 22, 2019 14:14
@encukou
Handle error in PyObject_RichCompareBool
b2e56da
@encukou
Add author to NEWS
21aee80
encukou
encukou approved these changes Oct 22, 2019
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Oct 22, 2019
@encukou encukou added the 🤖 automerge label Oct 22, 2019
@miss-islington

miss-islington commented Oct 22, 2019

Copy link
Copy Markdown
Contributor

@jdemeyer: Status check is done, and it's a success ✅ .

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Oct 22, 2019

Copy link
Copy Markdown
Contributor

Sorry, I can't merge this PR. Reason: Required status check "Azure Pipelines PR" is expected..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Oct 22, 2019

Copy link
Copy Markdown
Contributor

@jdemeyer: Status check is done, and it's a success ✅ .

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Oct 22, 2019

Copy link
Copy Markdown
Contributor

Sorry, I can't merge this PR. Reason: Required status check "Azure Pipelines PR" is expected..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Oct 22, 2019

Copy link
Copy Markdown
Contributor

@jdemeyer: Status check is done, and it's a success ✅ .

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Oct 22, 2019

Copy link
Copy Markdown
Contributor

Sorry, I can't merge this PR. Reason: Required status check "Azure Pipelines PR" is expected..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Oct 22, 2019

Copy link
Copy Markdown
Member

@zooba What's the best way to get Azure Pipelines to run on this PR?
I asked the same at #16497 (comment) and things got moving when I did. Was that you pushing a button somewhere?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jdemeyer

jdemeyer commented Oct 22, 2019

Copy link
Copy Markdown
Contributor Author

Thanks for going through with this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rlamy

rlamy commented Oct 31, 2019

Copy link
Copy Markdown
Contributor

Shouldn't format_kwargs_error be changed as well, to stay consistent with check_args_iterable?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Nov 5, 2019

Copy link
Copy Markdown
Member

Good catch, thank you!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou
Change format_kwargs_error to use _PyObject_FunctionStr as well
402ec96
@encukou
encukou force-pushed the funcstr branch from edef14c to 402ec96 Compare November 5, 2019 15:00
@encukou
Merge branch 'master' to resolve PyErr_Format/_PyErr_Format conflict
0307ce9
The conflicting change in master is to use _PyErr_Format
(with explicit thread state argument) instead of PyErr_Format
@miss-islington

miss-islington commented Nov 5, 2019

Copy link
Copy Markdown
Contributor

@jdemeyer: Status check is done, and it's a success ✅ .

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington
miss-islington merged commit bf17d41 into python:master Nov 5, 2019
@bedevere-bot bedevere-bot removed the awaiting merge label Nov 5, 2019
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
@jdemeyer Jake Taylor
bpo-37645: add new function _PyObject_FunctionStr() (pythonGH-14890)
80c322a
Additional note: the `method_check_args` function in `Objects/descrobject.c` is written in such a way that it applies to all kinds of descriptors. In particular, a future re-implementation of `wrapper_descriptor` could use that code.

CC @vstinner @encukou 


https://bugs.python.org/issue37645



Automerge-Triggered-By: @encukou
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
@jdemeyer @shihai1991
bpo-37645: add new function _PyObject_FunctionStr() (pythonGH-14890)
fe62c7d
Additional note: the `method_check_args` function in `Objects/descrobject.c` is written in such a way that it applies to all kinds of descriptors. In particular, a future re-implementation of `wrapper_descriptor` could use that code.

CC @vstinner @encukou 


https://bugs.python.org/issue37645



Automerge-Triggered-By: @encukou
@jdemeyer jdemeyer mentioned this pull request Oct 16, 2022
Replace PyEval_GetFuncName/PyEval_GetFuncDesc #81826
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@encukou encukou encukou approved these changes
+1 more reviewer
@ZackerySpytz ZackerySpytz ZackerySpytz left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@jdemeyer @vstinner @encukou @miss-islington @rlamy @serhiy-storchaka @ZackerySpytz @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.