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

spec_arg's __bool__ is called while initializing NonCallableMock #86698

Closed
idanw206 mannequin opened this issue Dec 2, 2020 · 4 comments
Closed

spec_arg's __bool__ is called while initializing NonCallableMock #86698

idanw206 mannequin opened this issue Dec 2, 2020 · 4 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@idanw206
Copy link
Mannequin

idanw206 mannequin commented Dec 2, 2020

BPO 42532
Nosy @cjw296, @voidspace, @lisroach, @mariocj89, @tirkarthi, @idanw206
PRs
  • bpo-42532: Check if NonCallableMock's spec_arg is not None instead of call its __bool__ function #23613
  • [3.9] bpo-42532: Check if NonCallableMock's spec_arg is not None instead of call its __bool__ function (GH-23613) #23676
  • 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 2020-12-06.22:45:57.462>
    created_at = <Date 2020-12-02.07:29:30.286>
    labels = ['3.8', 'type-bug', 'library', '3.9', '3.10']
    title = "spec_arg's __bool__ is called while initializing NonCallableMock"
    updated_at = <Date 2020-12-14.05:49:25.243>
    user = 'https://github.com/idanw206'

    bugs.python.org fields:

    activity = <Date 2020-12-14.05:49:25.243>
    actor = 'xtreak'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-12-06.22:45:57.462>
    closer = 'idanweiss97'
    components = ['Library (Lib)']
    creation = <Date 2020-12-02.07:29:30.286>
    creator = 'idanweiss97'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42532
    keywords = ['patch']
    message_count = 4.0
    messages = ['382403', '382483', '382590', '382952']
    nosy_count = 7.0
    nosy_names = ['cjw296', 'michael.foord', 'python-dev', 'lisroach', 'mariocj89', 'xtreak', 'idanweiss97']
    pr_nums = ['23613', '23676']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42532'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @idanw206 idanw206 mannequin added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 2, 2020
    @idanw206
    Copy link
    Mannequin Author

    idanw206 mannequin commented Dec 3, 2020

    To reproduce:
    import unittest.mock

    class LogicInBool:
        def __bool__(self):
            print("In Bool!")
            return True
    
    class SomeClass:
        def __init__(self):
            self.logic_in_bool = LogicInBool()
    
    obj = SomeClass()
    with unittest.mock.patch.object(obj, 'logic_in_bool', autospec=True):
        # "In Bool! is printed
        pass

    @tirkarthi
    Copy link
    Member

    The fix to check for None seems straightforward to me and is only needed for AsyncMock. I would wait for others thoughts on this.

    @cjw296
    Copy link
    Contributor

    cjw296 commented Dec 6, 2020

    New changeset c598a04 by idanw206 in branch 'master':
    bpo-42532: Check if NonCallableMock's spec_arg is not None instead of call its __bool__ function (GH23613)
    c598a04

    @idanw206 idanw206 mannequin closed this as completed Dec 6, 2020
    @idanw206 idanw206 mannequin closed this as completed Dec 6, 2020
    @tirkarthi
    Copy link
    Member

    New changeset 14f2a12 by Karthikeyan Singaravelan in branch '3.9':
    [3.9] bpo-42532: Check if NonCallableMock's spec_arg is not None instead of call its __bool__ function (GH-23613) (GH-23676)
    14f2a12

    @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.8 only security fixes 3.9 only security fixes 3.10 only security fixes 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