Issue 24298: Fix signature() to properly unwrap wrappers around bound methods
diff --git a/Lib/inspect.py b/Lib/inspect.py
index a91f749..49e66ce 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1911,6 +1911,14 @@
     # Was this function wrapped by a decorator?
     if follow_wrapper_chains:
         obj = unwrap(obj, stop=(lambda f: hasattr(f, "__signature__")))
+        if isinstance(obj, types.MethodType):
+            # If the unwrapped object is a *method*, we might want to
+            # skip its first parameter (self).
+            # See test_signature_wrapped_bound_method for details.
+            return _signature_internal(
+                obj,
+                follow_wrapper_chains=follow_wrapper_chains,
+                skip_bound_arg=skip_bound_arg)
 
     try:
         sig = obj.__signature__
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 8d92f82..58a6cd2 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -1939,6 +1939,19 @@
         with self.assertRaisesRegex(ValueError, 'invalid method signature'):
             self.signature(Test())
 
+    def test_signature_wrapped_bound_method(self):
+        # Issue 24298
+        class Test:
+            def m1(self, arg1, arg2=1) -> int:
+                pass
+        @functools.wraps(Test().m1)
+        def m1d(*args, **kwargs):
+            pass
+        self.assertEqual(self.signature(m1d),
+                         ((('arg1', ..., ..., "positional_or_keyword"),
+                           ('arg2', 1, ..., "positional_or_keyword")),
+                          int))
+
     def test_signature_on_classmethod(self):
         class Test:
             @classmethod