You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When mocking with unsafe=True the mocked instances don't receive the unsafe argument. #94478
When the feature Check against misspellings of assert etc. in mock was introduced, the unsafe flag was moved out from kwargs and defined as a named argument.
Previously since unsafe was implicitly part of kwargs, it was silently propagated from _patch class to the instantiation of the klass variable inside the __enter__ method.
But now, the unsafe flag as an explicitly named argument is not being propagated to the instantiation of the Klass variable.
Hence the Mock class is unable to set its internal attribute _mock_unsafe and will always be False regardless of whether the user set unsafe=True or not.
The test cases have to be updated to show this bug.
This bug was introduced in this commit: fdb9efc (bpo-41877) and only included in versions from Python 3.10.
Your environment
CPython versions tested on: 3.10, 3.11 and master branch.
@LakmalCaldera I see the patch on your fork for this. Is anything preventing a PR to the CPython repo so a core developer can review your change and address this issue?
Activity
pythongh-94478: Fix bug unsafe not set when patching
ryan-duve commentedon Jan 16, 2026
@LakmalCaldera I see the patch on your fork for this. Is anything preventing a PR to the CPython repo so a core developer can review your change and address this issue?