bpo-38473: Handle autospecced functions and methods used with attach_mock (GH-16784) (GH-18167)

If an autospecced object is attached using attach_mock the
child would be a function with mock object as attribute from
which signature has to be derived.

(cherry picked from commit 66b00a9d3aacf6ed49412f48743e4913104a2bb3)

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index e92ccf1..34f2dd7 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -825,6 +825,10 @@
             if child is None or isinstance(child, _SpecState):
                 break
             else:
+                # If an autospecced object is attached using attach_mock the
+                # child would be a function with mock object as attribute from
+                # which signature has to be derived.
+                child = _extract_mock(child)
                 children = child._mock_children
                 sig = child._spec_signature