Description: fix get_documenter monkey-patching for Sphinx 8.1
 obj needs to be passed as the second argument, not the first one.
Author: Dmitry Shachnev <mitya57@debian.org>
Forwarded: https://github.com/mpi4py/mpi4py/pull/677
Last-Update: 2025-08-24

--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -270,18 +270,19 @@ def _setup_autodoc(app):
 
     def get_documenter(*args, **kwargs):
         if hasattr(autosummary, "_get_documenter"):
-            obj, args = args[0], args[1:]
-            get_documenter = autosummary._get_documenter
+            obj = args[0]  # signature is (obj, parent, *, registry)
         else:
-            obj, args = args[1], (args[0], *args[2:])
-            get_documenter = autosummary.get_documenter
+            obj = args[1]  # signature is (app, obj, parent)
         if isinstance(obj, type) and issubclass(obj, BaseException):
             caller = sys._getframe().f_back.f_code.co_name
             if caller == "generate_autosummary_content":
                 if obj.__module__ == "mpi4py.MPI":
                     if obj.__name__ == "Exception":
                         return ExceptionDocumenterCustom
-        return get_documenter(obj, *args, **kwargs)
+        if hasattr(autosummary, "_get_documenter"):
+            return autosummary._get_documenter(obj, *args[1:], **kwargs)
+        else:
+            return autosummary.get_documenter(args[0], obj, *args[2:], **kwargs)
 
     from sphinx.ext.autosummary import generate
 
