Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-32571: Avoid raising unneeded AttributeError and silencing it in C code (alt).#5222

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedJan 17, 2018
edited by bedevere-bot
Loading

Add_PyObject_LookupAttr() and_PyObject_LookupAttrId() and use them in appropriate cases instead ofPyObject_GetAttr(),_PyObject_GetAttrId() and_PyObject_GetAttrIdWithoutError().

https://bugs.python.org/issue32571

Return -1 and set *result == NULL if an error other than AttributeError
is raised.
*/
PyAPI_FUNC(int) _PyObject_LookupAttr(PyObject *, PyObject *, PyObject **);
Copy link
Member

Choose a reason for hiding this comment

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

I would rename the method toPyObject_LookupAttr (no leading underscore). I'd use it in my libraries and the leading underscore would make me think that I shouldn't.

I also like Inada-san's suggestion to simplify the return value even further:

  • -1, if anunrelated error occurred during attribute lookup
  • 0 if no errors have occurred;*result will be set toNULL if the attribute was not found, and to a non-NULL value if it was found.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think this API is experimental and should be kept private for some time. We are still discussing it, and after making some design decision we may change it in future.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with@serhiy-storchaka.
While I feel this API is nice, I'm not sure we should set
*result=NULL when returning -1 or not.

Copy link
Member

Choose a reason for hiding this comment

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

Don't we care C API methods with a leading underscore the same as without? I've never seen us breaking the_ prefixed API to be honest. So leading underscore or not it's set in stone.

Copy link
Member

Choose a reason for hiding this comment

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

@1st1 Actually speaking, I broke_PyObject_GenericGetAttrWithDict(). I added one argument to suppress AttributeError.

1st1 reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. The PR is LGTM.

@serhiy-storchakaserhiy-storchaka added performancePerformance or resource usage skip news labelsJan 17, 2018
@methane
Copy link
Member

@serhiy-storchaka Would you merge this?
I want to use this API in#5273.

@1st1
Copy link
Member

I guess we can merge this ourselves if Serhiy isn't around. I'd like us to have this in 3.7.

@methanemethane merged commitf320be7 intopython:masterJan 25, 2018
@serhiy-storchakaserhiy-storchaka deleted the getattr-without-error-alt branchSeptember 22, 2018 19:04
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@methanemethanemethane approved these changes

@1st11st11st1 approved these changes

@rhettingerrhettingerAwaiting requested review from rhettinger

Assignees
No one assigned
Labels
performancePerformance or resource usageskip news
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@serhiy-storchaka@methane@1st1@the-knights-who-say-ni@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp