NiklasRosenstein / pydoc-markdown

Create Python API documentation in Markdown format.
http://niklasrosenstein.github.io/pydoc-markdown/
Other
453 stars 102 forks source link

not pretty formatting function definitions with type annotations #244

Closed kellyjonbrazil closed 2 years ago

kellyjonbrazil commented 2 years ago

Environment

Describe the bug

pydoc-markdown is not pretty formatting function definitions with type annotations.

I have a fairly involved function definition that I have formatted over several lines in my code, but pydoc-markdown seems to pull it all into a single line. Function definitions without type annotations seem to format nicely enough.

Is there a way to control this via configuration?

Here is my function definition:

def parse(
    parser_mod_name: str,
    data: Union[str, Iterable[str]],
    quiet: Optional[bool] = False,
    raw: Optional[bool] = False,
    ignore_exceptions: Optional[Union[None, bool]] = None,
    **kwargs: Any
) -> Union[Dict[str, Any], List[Dict[str, Any]], Iterator[Dict[str, Any]]]:

and here is the resulting code block in the markdown file:

def parse(parser_mod_name: str, data: Union[str, Iterable[str]], quiet: Optional[bool] = False, raw: Optional[bool] = False, ignore_exceptions: Optional[Union[None, bool]] = None, **kwargs: Any) -> Union[Dict[str, Any], List[Dict[str, Any]], Iterator[Dict[str, Any]]]

pydoc-markdown doesn't seem to pull the yapf configuration from my .style.yapf file. I wonder if that would be an option if it is not already configurable?

Expected behavior

I would like to be able to have each argument on its own line as can be achieved with SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED: True in yapf style configuration.

thedemons commented 2 years ago

I also had this problem and had to modify the renderer. This is simply because pydoc-markdown read the source code into a docspec.ApiObject then parsing it to text. So it loses all spacings and line breaks.

I use black formatter to beautify the code. Maybe I'll open a pull request in a couple of days adding this feature.

kellyjonbrazil commented 2 years ago

not sure if this PR is relevant: https://github.com/NiklasRosenstein/pydoc-markdown/pull/78

NiklasRosenstein commented 2 years ago

Hey all, inspired by @lgeiger's original PR (#78), I've added formatting the function, class and variable signatures with YAPF to the MarkdownRenderer in this PR: https://github.com/NiklasRosenstein/pydoc-markdown/pull/245. It'll be part of the 4.6.0 release.