[Python-checkins] Remove unused branches from mock module (#106617)

cjw296 webhook-mailer at python.org
Tue Jul 11 04:52:16 EDT 2023


https://github.com/python/cpython/commit/e6379f72cbc60f6b3c5676f9e225d4f145d5693f
commit: e6379f72cbc60f6b3c5676f9e225d4f145d5693f
branch: main
author: Chris Withers <chris at withers.org>
committer: cjw296 <chris at withers.org>
date: 2023-07-11T08:52:12Z
summary:

Remove unused branches from mock module (#106617)

* lambda has a name of __none__, but no async lambda so this branch is not needed

* _get_signature_object only returns None for bound builtins. There are no async builtins so this branch isn't needed

* Exclude  a couple of methods from coverage checking in the downstream rolling backport of mock

files:
M Lib/test/test_unittest/testmock/testthreadingmock.py
M Lib/unittest/mock.py

diff --git a/Lib/test/test_unittest/testmock/testthreadingmock.py b/Lib/test/test_unittest/testmock/testthreadingmock.py
index c6f179490d01f..b6e12bcb3cda9 100644
--- a/Lib/test/test_unittest/testmock/testthreadingmock.py
+++ b/Lib/test/test_unittest/testmock/testthreadingmock.py
@@ -11,10 +11,10 @@
 
 class Something:
     def method_1(self):
-        pass
+        pass  # pragma: no cover
 
     def method_2(self):
-        pass
+        pass  # pragma: no cover
 
 
 class TestThreadingMock(unittest.TestCase):
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 3ed54b3ba230e..e8c8360e0ae13 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -212,17 +212,12 @@ def _set_async_signature(mock, original, instance=False, is_async_mock=False):
     # signature as the original.
 
     skipfirst = isinstance(original, type)
-    result = _get_signature_object(original, instance, skipfirst)
-    if result is None:
-        return mock
-    func, sig = result
+    func, sig = _get_signature_object(original, instance, skipfirst)
     def checksig(*args, **kwargs):
         sig.bind(*args, **kwargs)
     _copy_func_details(func, checksig)
 
     name = original.__name__
-    if not name.isidentifier():
-        name = 'funcopy'
     context = {'_checksig_': checksig, 'mock': mock}
     src = """async def %s(*args, **kwargs):
     _checksig_(*args, **kwargs)



More information about the Python-checkins mailing list