Skip to content
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

bpo-33261: guard access to __code__ attribute in inspect #6448

Merged
merged 1 commit into from
Apr 2, 2019

Conversation

jdemeyer
Copy link
Contributor

@jdemeyer jdemeyer commented Apr 11, 2018

@jdemeyer
Copy link
Contributor Author

An alternative solution, closer to the original code, would be

def _have_code_flag(func, flag):
    """Return true if the function ``func`` has a code object with
    ``flag`` in its flags."""
    if ismethod(func):
        func = func.__func__
    return isfunction(func) and bool(code.co_flags & flag)

@encukou
Copy link
Member

encukou commented May 10, 2018

The isgeneratorfunction docstring now says:

 Generator function objects provide the same attributes as functions.
 See help(isfunction) for a list of attributes

I don't think the PR as it is (i.e. checking for __code__) gives a strong enough guarantee for that. It's not apparent that __code__ is reserved for functions only. I'm worried about us adding __code__ to something unrelated in the future, without regard to how inspect uses it.

So I'm leaning towards the alternative solution, keeping the isfunction/ismethod calls.

@jdemeyer jdemeyer force-pushed the bpo33261 branch 2 times, most recently from 0d704d8 to b04a213 Compare May 14, 2018 08:23
@jdemeyer
Copy link
Contributor Author

I updated the branch with explit ismethod and isfunction checks.

@jdemeyer
Copy link
Contributor Author

jdemeyer commented Oct 9, 2018

Branch rebased to latest master. Please review...

@jdemeyer
Copy link
Contributor Author

CC @1st1 as suggested by https://devguide.python.org/experts/

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

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

I am OK with this implementation.

@jdemeyer
Copy link
Contributor Author

I am OK with this implementation.

So, are you willing to actually merge it (or add the automerge label)?

Lib/test/inspect_fodder.py Show resolved Hide resolved
@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@jdemeyer
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@encukou, @1st1: please review the changes made to this pull request.

@encukou encukou merged commit fcef60f into python:master Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants