classification
Title: spec_arg's __bool__ is called while initializing NonCallableMock
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cjw296, idanweiss97, lisroach, mariocj89, michael.foord, python-dev, xtreak
Priority: normal Keywords: patch

Created on 2020-12-02 07:29 by idanweiss97, last changed 2020-12-14 05:49 by xtreak. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23613 merged python-dev, 2020-12-02 07:35
PR 23676 merged xtreak, 2020-12-07 12:50
Messages (4)
msg382403 - (view) Author: Idan Weiss (idanweiss97) * Date: 2020-12-03 12:20
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
msg382483 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-12-04 12:48
The fix to check for None seems straightforward to me and is only needed for AsyncMock. I would wait for others thoughts on this.
msg382590 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2020-12-06 09:59
New changeset c598a04dd29b89ad072245ddaf738badcfb41ac7 by idanw206 in branch 'master':
bpo-42532: Check if NonCallableMock's spec_arg is not None instead of call its __bool__ function (GH23613)
https://github.com/python/cpython/commit/c598a04dd29b89ad072245ddaf738badcfb41ac7
msg382952 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-12-14 05:49
New changeset 14f2a124e20081b8981c8d6165dbd78d11b6808c 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)
https://github.com/python/cpython/commit/14f2a124e20081b8981c8d6165dbd78d11b6808c
History
Date User Action Args
2020-12-14 05:49:25xtreaksetmessages: + msg382952
2020-12-07 12:50:41xtreaksetpull_requests: + pull_request22542
2020-12-06 22:45:57idanweiss97setstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-12-06 09:59:59cjw296setmessages: + msg382590
2020-12-04 12:48:02xtreaksetnosy: + cjw296, michael.foord, lisroach, mariocj89, xtreak
messages: + msg382483
2020-12-03 12:20:26idanweiss97setmessages: + msg382403
2020-12-02 07:35:11python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request22480
stage: patch review
2020-12-02 07:29:30idanweiss97create