Skip to content

Commit 08e61b9

Browse files
committed
Fixed displaying "self" in class signatures
1 parent 5faec73 commit 08e61b9

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

autoapi/mappers/python/mapper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,10 @@ def create_class(self, data, options=None, **kwargs):
406406
yield obj
407407

408408
def _record_typehints(self, obj):
409-
if isinstance(
410-
obj, (PythonClass, PythonFunction, PythonMethod)
411-
) and not obj.overloads:
409+
if (
410+
isinstance(obj, (PythonClass, PythonFunction, PythonMethod))
411+
and not obj.overloads
412+
):
412413
obj_annotations = {}
413414

414415
include_return_annotation = True

autoapi/mappers/python/objects.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
LOGGER = sphinx.util.logging.getLogger(__name__)
1010

1111

12-
def _format_args(args_info, include_annotations=True):
12+
def _format_args(args_info, include_annotations=True, ignore_self=None):
1313
result = []
1414

15-
for prefix, name, annotation, default in args_info:
15+
for i, (prefix, name, annotation, default) in enumerate(args_info):
16+
if i == 0 and name == ignore_self:
17+
continue
1618
formatted = "{}{}{}{}".format(
1719
prefix or "",
1820
name or "",
@@ -351,14 +353,14 @@ def args(self):
351353
args = ""
352354

353355
if self.constructor:
354-
autodoc_typehints = getattr(self.app.config, "autodoc_typehints", "signature")
356+
autodoc_typehints = getattr(
357+
self.app.config, "autodoc_typehints", "signature"
358+
)
355359
show_annotations = autodoc_typehints != "none" and not (
356360
autodoc_typehints == "description" and not self.constructor.overloads
357361
)
358362
args_data = self.constructor.obj["args"]
359-
if args_data and args_data[0][1] == "self":
360-
args_data = args_data[1:]
361-
args = _format_args(args_data, show_annotations)
363+
args = _format_args(args_data, show_annotations, ignore_self="self")
362364

363365
return args
364366

@@ -368,10 +370,15 @@ def overloads(self):
368370

369371
if self.constructor:
370372
overload_data = self.constructor.obj["overloads"]
371-
if overload_data and overload_data[0][1] == "self":
372-
overload_data = overload_data[1:]
373+
autodoc_typehints = getattr(
374+
self.app.config, "autodoc_typehints", "signature"
375+
)
376+
show_annotations = autodoc_typehints not in ("none", "description")
373377
overloads = [
374-
(_format_args(args), return_annotation)
378+
(
379+
_format_args(args, show_annotations, ignore_self="self"),
380+
return_annotation,
381+
)
375382
for args, return_annotation in overload_data
376383
]
377384

tests/python/test_pyintegration.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ def build(test_dir, confoverrides=None, **kwargs):
5151
class TestSimpleModule:
5252
@pytest.fixture(autouse=True, scope="class")
5353
def built(self, builder):
54-
builder("pyexample", warningiserror=True, confoverrides={"suppress_warnings": ["app"]})
54+
builder(
55+
"pyexample",
56+
warningiserror=True,
57+
confoverrides={"suppress_warnings": ["app"]},
58+
)
5559

5660
def test_integration(self):
5761
self.check_integration("_build/text/autoapi/example/index.txt")

0 commit comments

Comments
 (0)