From e6379f72cbc60f6b3c5676f9e225d4f145d5693f Mon Sep 17 00:00:00 2001 From: Chris Withers Date: Tue, 11 Jul 2023 09:52:12 +0100 Subject: 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 --- Lib/test/test_unittest/testmock/testthreadingmock.py | 4 ++-- Lib/unittest/mock.py | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_unittest/testmock/testthreadingmock.py b/Lib/test/test_unittest/testmock/testthreadingmock.py index c6f1794..b6e12bc 100644 --- a/Lib/test/test_unittest/testmock/testthreadingmock.py +++ b/Lib/test/test_unittest/testmock/testthreadingmock.py @@ -11,10 +11,10 @@ threading_helper.requires_working_threading(module=True) 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 3ed54b3..e8c8360 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) -- cgit v0.12