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-29403: Fix mock's broken autospec behavior on method-bound builtin functions#3

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

Conversation

habnabit
Copy link
Contributor

http://bugs.python.org/issue29403

Cython will, in the right circumstances, offer a MethodType instance
where im_func is a builtin function. Any instance of MethodType is
automatically assumed to be a python-defined function (more
specifically, a function that has an inspectable signature), but
_set_signature was still conservative in its assumptions. As a result
_set_signature would return early with None instead of a mock since the
im_func had no inspectable signature. This causes problems deeper inside
mock, as _set_signature is assumed toalways return a mock, and
nothing checked its return value.

In similar corner cases, autospec will simply not check the spec of the
function, so _set_signature is amended to now return early with the
original, not-wrapped mock object.

shalabhc reacted with thumbs up emoji
@the-knights-who-say-ni

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed thePSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username onbugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow these steps to help rectify the issue:

  1. If you don't have an account on b.p.o, pleasecreate one
  2. Make sure your GitHub username is listed in "Your Details" at b.p.o
  3. If you have not already done so, please sign thePSF contributor agreement
  4. If you just signed the CLA, pleasewait at least a day and then check "Your Details" onbugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  5. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

@habnabit
Copy link
ContributorAuthor

I signed the CLA when I opened the bug on bpo last week, but my account doesn't say received still:http://bugs.python.org/user25445

@ShalbafZadeh
Copy link

@habnabit
have you added you github username to your bpo account?
i can't see it
https://bugs.python.org/user6636

@habnabit
Copy link
ContributorAuthor

@ShalbafZadeh that was an old account; I made a new one last week from a newer openid provider.http://bugs.python.org/user25445 is the new one, which I'm logged into now.

ShalbafZadeh reacted with thumbs up emoji

@ShalbafZadeh
Copy link

@habnabit seems odd

@habnabithabnabitforce-pushed thefix-mock-builtin-methods-for-cython branch fromc8bc9c9 to9148028CompareFebruary 11, 2017 01:47
@habnabit
Copy link
ContributorAuthor

Rebased and pushed, including a test fix. The third-party mock usedsix, and the stdlib does not includesix.

@habnabithabnabitforce-pushed thefix-mock-builtin-methods-for-cython branch 2 times, most recently frome12a088 to97bb733CompareFebruary 11, 2017 06:25
@habnabit
Copy link
ContributorAuthor

Rebased again!

@codecov
Copy link

codecovbot commentedFeb 11, 2017

Codecov Report

Merging#3 intomaster willincrease coverage by<.01%.

@@            Coverage Diff             @@##           master       #3      +/-   ##==========================================+ Coverage   82.37%   82.37%   +<.01%==========================================  Files        1427     1427                Lines      350948   350959      +11     ==========================================+ Hits       289088   289104      +16+ Misses      61860    61855       -5

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last updatee7ffb99...97bb733. Read thecomment docs.

Copy link
Member

@berkerpeksagberkerpeksag left a comment

Choose a reason for hiding this comment

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

I haven't had a time to dive into the whole life cycle of_set_signature() yet, but from a quick glance it looks good to me.

@berkerpeksag
Copy link
Member

Please add an entry toMisc/NEWS. It should be in the "Library" section.

@habnabithabnabitforce-pushed thefix-mock-builtin-methods-for-cython branch from97bb733 toc5b3653CompareFebruary 23, 2017 22:40
@habnabit
Copy link
ContributorAuthor

Okay, rebased and added a NEWS entry.

@Yhg1s
Copy link
Member

This change looks good to me: returning None does not make sense in the one place where _set_signature is called, and I don't think there's a better solution here. If the code wants to try harder and figure out what signature to use, that would be a change to _get_signature, not _set_signature, and this change would still make sense.

@voidspace, do you want to take a look, or can we merge?

@buhtz
Copy link

Can we merge this?

habnabitand others added2 commitsJuly 20, 2017 02:33
Cython will, in the right circumstances, offer a MethodType instancewhere im_func is a builtin function. Any instance of MethodType isautomatically assumed to be a python-defined function (morespecifically, a function that has an inspectable signature), but_set_signature was still conservative in its assumptions. As a result_set_signature would return early with None instead of a mock since theim_func had no inspectable signature. This causes problems deeper insidemock, as _set_signature is assumed to _always_ return a mock, andnothing checked its return value.In similar corner cases, autospec will simply not check the spec of thefunction, so _set_signature is amended to now return early with theoriginal, not-wrapped mock object.
@berkerpeksagberkerpeksagforce-pushed thefix-mock-builtin-methods-for-cython branch from75ad0f4 to989e99aCompareJuly 19, 2017 23:35
@berkerpeksagberkerpeksag merged commit856cbcc intopython:masterJul 20, 2017
jaraco pushed a commit that referenced this pull requestDec 2, 2022
nanjekyejoannah added a commit to nanjekyejoannah/cpython that referenced this pull requestJan 11, 2023
3: Add Py2x flag r=ltratt a=nanjekyejoannahThis PR adds the Py2x flag:```Python 3.12.0a0 (heads/migration-dirty:5842fee697, May 23 2022, 00:25:04) [Clang 12.0.0 (clang-1200.0.32.29)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import sys>>> sys.flagssys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, py2x_warning=1, quiet=0, hash_randomization=1, isolated=0, dev_mode=False, utf8_mode=0, warn_default_encoding=0)>>> ```Co-authored-by: Joannah Nanjekye <jnanjekye@python.org>
nanjekyejoannah added a commit to nanjekyejoannah/cpython that referenced this pull requestJan 11, 2023
5: Add 2.x related warnings r=ltratt a=nanjekyejoannahI have broken away the warning bit from the [flag](python#3 ) and the [port ](python#4 )PR. Well, the way function calls are done between C and Python is confusing, nothing scary anyway, review maybe a bit annoying.Review this PR beforepython#4 Co-authored-by: Joannah Nanjekye <jnanjekye@python.org>
barneygale added a commit to barneygale/cpython that referenced this pull requestOct 29, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@berkerpeksagberkerpeksagberkerpeksag approved these changes

@auvipyauvipyauvipy approved these changes

@voidspacevoidspaceAwaiting requested review from voidspace

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

10 participants
@habnabit@the-knights-who-say-ni@ShalbafZadeh@berkerpeksag@Yhg1s@buhtz@voidspace@bedevere-bot@auvipy@Mariatta

[8]ページ先頭

©2009-2025 Movatter.jp