Skip to content

Commit

Permalink
Merge pull request #21 from mkdocstrings/issue-17-return-types
Browse files Browse the repository at this point in the history
#17 Show return types
  • Loading branch information
rudolfbyker authored Sep 20, 2024
2 parents 14d0fca + 6ef364a commit bd426a4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 22 deletions.
4 changes: 4 additions & 0 deletions examples/example1/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

::: src/foo.bas
handler: vba
options:
heading_level: 3

## `bar/baz.bas`

::: src/bar/baz.bas
handler: vba
options:
heading_level: 3
3 changes: 3 additions & 0 deletions examples/example1/src/foo.bas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Function fuzz_HotelEcho_helper( _
' Name: The name
' description: The description
'
' Returns:
' A fancy ListObject
'
' Examples:
' >>> fuzz_HotelEcho_helper(sheet, "foo", "the sheet")
' ListObject(...)
Expand Down
22 changes: 8 additions & 14 deletions mkdocstrings_handlers/vba/_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,10 @@ def render(
)

return template.render(
**{
"config": final_config,
"module": data,
"heading_level": heading_level,
"root": True,
},
config=final_config,
module=data,
heading_level=heading_level,
root=True,
)

def update_env(self, md: Markdown, config: Dict[Any, Any]) -> None:
Expand All @@ -177,23 +175,19 @@ def get_anchors(self, data: VbaModuleInfo) -> Tuple[str, ...]:

def get_handler(
*,
theme: str,
theme: str = "material",
custom_templates: str | None = None,
config_file_path: str | None = None,
paths: list[str] | None = None,
locale: str = "en",
**config: Any,
**kwargs: Any,
) -> VbaHandler:
"""
Simply return an instance of `VbaHandler`.
Get a new `VbaHandler`.
Arguments:
theme: The theme to use when rendering contents.
custom_templates: Directory containing custom templates.
config_file_path: The MkDocs configuration file path.
paths: A list of paths to use as Griffe search paths.
locale: The locale to use when rendering content.
**config: Configuration passed to the handler.
kwargs: Extra keyword arguments that we don't use.
Returns:
An instance of `VbaHandler`.
Expand Down
3 changes: 2 additions & 1 deletion mkdocstrings_handlers/vba/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def find_procedures(code: str) -> Generator[VbaProcedureInfo, None, None]:

docstring_value = "\n".join(uncomment_lines(docstring_lines))

# See https://mkdocstrings.github.io/griffe/usage/#using-griffe-as-a-docstring-parsing-library
# See https://mkdocstrings.github.io/griffe/guide/users/how-to/parse-docstrings/
docstring = Docstring(
value=docstring_value,
parser=Parser.google,
Expand All @@ -180,6 +180,7 @@ def find_procedures(code: str) -> Generator[VbaProcedureInfo, None, None]:
for arg in procedure["signature"].args
)
),
returns=procedure["signature"].return_type,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
toc_label=procedure.signature.name ~ "()") %}

{% if config.separate_signature %}
{{ procedure.signature.name }}()
{{ procedure.signature.visibility }} {{ procedure.signature.procedure_type }} {{ procedure.signature.name }}()
{% else %}
{% filter highlight(language="vba", inline=True) %}
{{ procedure.signature.name }}
{{ procedure.signature.visibility }} {{ procedure.signature.procedure_type }} {{ procedure.signature.name }}
{% include "signature.html" with context %}
{% endfilter %}
{% endif %}
Expand Down
8 changes: 5 additions & 3 deletions test/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from contextlib import contextmanager
from logging import WARNING
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Generator
Expand Down Expand Up @@ -29,9 +30,10 @@ def tmp_build(config_file_path: Path) -> Generator[Path, None, None]:

class TestExamples(unittest.TestCase):
def test_example1(self) -> None:
with tmp_build(examples_dir.joinpath("example1", "mkdocs.yml")) as tmp_dir:
# TODO: Write assertions. For now, just check that it does not fail.
pass
with self.assertNoLogs(level=WARNING):
with tmp_build(examples_dir.joinpath("example1", "mkdocs.yml")) as tmp_dir:
# TODO: Write assertions. For now, just check that it does not fail.
pass


if __name__ == "__main__":
Expand Down
14 changes: 12 additions & 2 deletions test/util/test_parse_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,20 @@ def test_1(self) -> None:
),
),
(
"Function Test(Optional d As Variant = Empty)",
"Public Property Get asdf() As String",
VbaSignatureInfo(
visibility="Public",
return_type="String",
procedure_type="Property Get",
name="asdf",
args=[],
),
),
(
"Function Test(Optional d As Variant = Empty) As String",
VbaSignatureInfo(
visibility=None,
return_type=None,
return_type="String",
procedure_type="Function",
name="Test",
args=[
Expand Down

0 comments on commit bd426a4

Please sign in to comment.