Skip to content

Commit 434e4e7

Browse files
authored
Merge pull request #271 from machow/fix-no-render-self
Fix no render self
2 parents 10401b7 + 7372f67 commit 434e4e7

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

quartodoc/renderers/md_renderer.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def _fetch_object_dispname(self, el: "dc.Alias | dc.Object"):
9999
return el.canonical_path
100100

101101
raise ValueError(f"Unsupported display_name: `{self.display_name}`")
102+
103+
def _fetch_method_parameters(self, el: dc.Function):
104+
# adapted from mkdocstrings-python jinja tempalate
105+
if el.parent and el.parent.is_class and len(el.parameters) > 0:
106+
if el.parameters[0].name in {"self", "cls"}:
107+
return dc.Parameters(*list(el.parameters)[1:])
108+
109+
return el.parameters
102110

103111
def _render_table(self, rows, headers):
104112
table = tabulate(rows, headers=headers, tablefmt="github")
@@ -162,7 +170,7 @@ def signature(
162170
self, el: Union[dc.Class, dc.Function], source: Optional[dc.Alias] = None
163171
):
164172
name = self._fetch_object_dispname(source or el)
165-
pars = self.render(el.parameters)
173+
pars = self.render(self._fetch_method_parameters(el))
166174

167175
return f"`{name}({pars})`"
168176

quartodoc/tests/__snapshots__/test_renderers.ambr

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@
5454

5555
| Name | Description |
5656
| --- | --- |
57+
| [some_class_method](#quartodoc.tests.example_class.C.some_class_method) | A class method |
5758
| [some_method](#quartodoc.tests.example_class.C.some_method) | A method |
5859

60+
### some_class_method { #quartodoc.tests.example_class.C.some_class_method }
61+
62+
`tests.example_class.C.some_class_method()`
63+
64+
A class method
65+
5966
### some_method { #quartodoc.tests.example_class.C.some_method }
6067

61-
`tests.example_class.C.some_method(self)`
68+
`tests.example_class.C.some_method()`
6269

6370
A method
6471
'''
@@ -105,11 +112,18 @@
105112

106113
| Name | Description |
107114
| --- | --- |
115+
| [some_class_method](#quartodoc.tests.example_class.C.some_class_method) | A class method |
108116
| [some_method](#quartodoc.tests.example_class.C.some_method) | A method |
109117

118+
## some_class_method { #quartodoc.tests.example_class.C.some_class_method }
119+
120+
`tests.example_class.C.some_class_method()`
121+
122+
A class method
123+
110124
## some_method { #quartodoc.tests.example_class.C.some_method }
111125

112-
`tests.example_class.C.some_method(self)`
126+
`tests.example_class.C.some_method()`
113127

114128
A method
115129
'''

quartodoc/tests/example_class.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def some_method(self):
2929
def some_property(self):
3030
"""A property"""
3131

32+
@classmethod
33+
def some_class_method(cls):
34+
"""A class method"""
35+
3236
class D:
3337
"""A nested class"""
3438

quartodoc/tests/test_builder_blueprint.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,19 @@ def _check_member_names(members, expected):
183183
[
184184
("attributes", {"some_property", "z", "SOME_ATTRIBUTE"}),
185185
("classes", {"D"}),
186-
("functions", {"some_method"}),
186+
("functions", {"some_method", "some_class_method"}),
187187
],
188188
)
189189
def test_blueprint_fetch_members_include_kind_false(kind, removed):
190190
option = {f"include_{kind}": False}
191-
all_members = {"SOME_ATTRIBUTE", "z", "some_property", "some_method", "D"}
191+
all_members = {
192+
"SOME_ATTRIBUTE",
193+
"z",
194+
"some_property",
195+
"some_method",
196+
"D",
197+
"some_class_method",
198+
}
192199

193200
auto = lo.Auto(name="quartodoc.tests.example_class.C", **option)
194201
bp = blueprint(auto)

0 commit comments

Comments
 (0)