Skip to content

Add support to custom sections on Google docstrings - #5

Closed
pslacerda wants to merge 6 commits into
rr-:masterfrom
pslacerda:master
Closed

pslacerda wants to merge 6 commits into
rr-:masterfrom
pslacerda:master

Conversation

@pslacerda

Copy link
Copy Markdown

It is parsed into a DocstringMeta.

It is parsed into a DocstringMeta.
@pslacerda

Copy link
Copy Markdown
Author

In my actual usage I'm monkey patching to support a style similar to google:

import docstring_parser.parser.google, re
docstring_parser.parser.google._sections = {
    "ARGUMENTS": "param",
    "EXAMPLES": "examples",
}
docstring_parser.parser.google._titles_re = re.compile(
    "^(" + "|".join("(%s)" % t for t in docstring_parser.parser.google._sections) + ")", flags=re.M
)
docstring_parser.parser.google._valid = {t for t, a in docstring_parser.parser.google._sections.items() if a}

@rr-

rr- commented Nov 26, 2019

Copy link
Copy Markdown
Owner

@pslacerda can you add tests for this?

@pslacerda

Copy link
Copy Markdown
Author

Sure I can. I do need Notes, Note and Example also, beside Examples. Should I add these too?

@rr-

rr- commented Nov 26, 2019

Copy link
Copy Markdown
Owner

Yes.

If you're feeling adventurous, you could refactor it so that extending the library for whatever sections you need is possible and doesn't require such hacks.

Comment thread docstring_parser/parser/google.py Resolved
Comment thread docstring_parser/parser/google.py Resolved
@pslacerda

Copy link
Copy Markdown
Author

I was feeling adventurous, just finished the code. Even with it a bit ugly, it is working for my case. I expect it to be an usual case.

@pslacerda

Copy link
Copy Markdown
Author

-- I'd rather preferred GoogleParser.
-- Me too!
[Closed]

@rr- rr- left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Excellent work, though I don't understand the last comment. I requested only some cosmetic changes.

Comment thread docstring_parser/parser/google.py Resolved
Comment thread docstring_parser/parser/google.py Resolved
@pslacerda

Copy link
Copy Markdown
Author

I was trying to say that maybe it could be like:

class GoogleParser:
    """New API for custom sections"""
    _sections: ...
    _title_colon: ...
    _titles_re: ...
    _valid: ...

    def __init__(sections=None, title_colon=True): pass
    def parse(): pass
    def add_section(): pass
    def _build_meta(): pass

def parse(s):
    """Old & easy API keep as it was."""
    return GoogleParser().parse(s)

But now I like the way it turned.

@pslacerda

Copy link
Copy Markdown
Author

Just tried with classes, see if you like. Also things that looks like titles but aren't titles are now description.

@pslacerda pslacerda changed the title Add support to Example sections on Google docstrings Add support to custom sections on Google docstrings Nov 28, 2019
@rr-

rr- commented Dec 18, 2019

Copy link
Copy Markdown
Owner

@pslacerda thanks, beautiful work. Merged. LMK if you need a new version on PyPI.

@rr- rr- closed this Dec 18, 2019
@pslacerda

Copy link
Copy Markdown
Author

@rr- seems you merged local but didn't pushed to Github.
I want to show the usage briefly in the README. Then a new version would be more than welcome.

@rr-

rr- commented Dec 18, 2019 •

Copy link
Copy Markdown
Owner

@pslacerda haha you're right :D I just pushed the changes. OK, LMK once you document the changes and we'll release a new version. Also, I apologize for the late reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants