Navigation Menu

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

mock's autospec's behavior on method-bound builtin functions is broken #73589

Closed
habnabit mannequin opened this issue Jan 31, 2017 · 7 comments
Closed

mock's autospec's behavior on method-bound builtin functions is broken #73589

habnabit mannequin opened this issue Jan 31, 2017 · 7 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@habnabit
Copy link
Mannequin

habnabit mannequin commented Jan 31, 2017

BPO 29403
Nosy @voidspace, @berkerpeksag, @habnabit, @csabella
PRs
  • bpo-29403: Fix mock's broken autospec behavior on method-bound builtin functions #3
  • [3.6] bpo-29403: Fix mock's broken autospec behavior on method-bound builtin functions (GH-3) #2807
  • [3.5] bpo-29403: Fix mock's broken autospec behavior on method-bound builtin functions (GH-3) #2809
  • Files
  • mock.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-07-21.23:27:59.508>
    created_at = <Date 2017-01-31.23:01:55.161>
    labels = ['3.7', 'type-bug', 'library']
    title = "mock's autospec's behavior on method-bound builtin functions is broken"
    updated_at = <Date 2017-07-21.23:27:59.506>
    user = 'https://github.com/habnabit'

    bugs.python.org fields:

    activity = <Date 2017-07-21.23:27:59.506>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-07-21.23:27:59.508>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2017-01-31.23:01:55.161>
    creator = 'Aaron Gallagher'
    dependencies = []
    files = ['46468']
    hgrepos = []
    issue_num = 29403
    keywords = ['patch']
    message_count = 7.0
    messages = ['286565', '286566', '295249', '298696', '298827', '298828', '298829']
    nosy_count = 4.0
    nosy_names = ['michael.foord', 'berker.peksag', 'Aaron Gallagher', 'cheryl.sabella']
    pr_nums = ['3', '2807', '2809']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29403'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @habnabit
    Copy link
    Mannequin Author

    habnabit mannequin commented Jan 31, 2017

    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 to always 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.

    There is another None early return in _set_signature, but it seems.. harder to trigger? It seems more appropriate to raise an exception there if this is being fixed.

    @habnabit habnabit mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 31, 2017
    @habnabit
    Copy link
    Mannequin Author

    habnabit mannequin commented Jan 31, 2017

    Patch adapted from testing-cabal/mock#389

    @csabella
    Copy link
    Contributor

    csabella commented Jun 6, 2017

    This PR appears to have been approved, perhaps pending input from michael.foord?

    @berkerpeksag
    Copy link
    Member

    New changeset 856cbcc by Berker Peksag (Aaron Gallagher) in branch 'master':
    bpo-29403: Fix mock's broken autospec behavior on method-bound builtin functions (GH-3)
    856cbcc

    @berkerpeksag
    Copy link
    Member

    New changeset 64b9a15 by Berker Peksag in branch '3.6':
    [3.6] bpo-29403: Fix mock's broken autospec behavior on method-bound builtin functions (GH-3)
    64b9a15

    @berkerpeksag
    Copy link
    Member

    New changeset e78dc0a by Berker Peksag in branch '3.5':
    [3.5] bpo-29403: Fix mock's broken autospec behavior on method-bound builtin functions (GH-3)
    e78dc0a

    @berkerpeksag
    Copy link
    Member

    Thank you for the PR, Aaron!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants