Skip to content

Commit

Permalink
Fix union in return type (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh9 authored Aug 18, 2023
1 parent 703c6ca commit 7ac25ab
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
__pycache__
*.egg-info
poetry.lock
.idea/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# (Fork) 0.0.1 (2023-08-18)

- Google: Fixed a bug where union style return types (such as `int | str`) are not parsed correctly

# 0.15 (2022-09-05)

- Parser: add a new function, `parse_from_object`, that supports scattered
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
docstring_parser
docstring_parser_fork
================

This is a fork of [docstring_parser](https://github.com/rr-/docstring_parser). The reason I'm forking that is to quickly get some bug fixes out for users of [pydoclint](https://github.com/jsh9/pydoclint).

------

[![Build](https://github.com/rr-/docstring_parser/actions/workflows/build.yml/badge.svg)](https://github.com/rr-/docstring_parser/actions/workflows/build.yml)

Parse Python docstrings. Currently support ReST, Google, Numpydoc-style and
Expand Down Expand Up @@ -42,13 +46,13 @@ Read [API Documentation](https://rr-.github.io/docstring_parser/).
Installation using pip

```shell
pip install docstring_parser
pip install docstring_parser_fork

# or if you want to install it in a virtual environment

python -m venv venv # create environment
source venv/bin/activate # activate environment
python -m pip install docstring_parser
python -m pip install docstring_parser_fork
```

Installation using conda
Expand Down
2 changes: 1 addition & 1 deletion docstring_parser/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Section(namedtuple("SectionBase", "title key type")):

GOOGLE_TYPED_ARG_REGEX = re.compile(r"\s*(.+?)\s*\(\s*(.*[^\s]+)\s*\)")
GOOGLE_ARG_DESC_REGEX = re.compile(r".*\. Defaults to (.+)\.")
MULTIPLE_PATTERN = re.compile(r"(\s*[^:\s]+:)|([^:]*\]:.*)")
MULTIPLE_PATTERN = re.compile(r"(\s*[^:\s]+:)|([^:]*\]:.*)|(\s*[^|\s]+(\s*\|\s*[^|\s]+)*:)") # noqa: E501

DEFAULT_SECTIONS = [
Section("Arguments", "param", SectionType.MULTIPLE),
Expand Down
14 changes: 14 additions & 0 deletions docstring_parser/tests/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,20 @@ def test_returns() -> None:
assert len(docstring.many_returns) == 1
assert docstring.many_returns[0] == docstring.returns

docstring = parse(
"""
Short description
Returns:
str | int|None | bool: A description: with a colon
"""
)
assert docstring.returns is not None
assert docstring.returns.type_name == "str | int|None | bool"
assert docstring.returns.description == "A description: with a colon"
assert docstring.many_returns is not None
assert len(docstring.many_returns) == 1
assert docstring.many_returns[0] == docstring.returns

docstring = parse(
"""
Returns:
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "docstring_parser"
version = "0.15"
name = "docstring_parser_fork"
version = "0.0.1"
description = "Parse Python docstrings in reST, Google and Numpydoc format"
authors = ["Marcin Kurczewski <[email protected]>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/rr-/docstring_parser"
repository = "https://github.com/jsh9/docstring_parser_fork"
classifiers = [
"Environment :: Other Environment",
"Development Status :: 4 - Beta",
Expand Down Expand Up @@ -43,7 +43,7 @@ line-length = 79
py36 = true

[tool.isort]
known_third_party = "docstring_parser"
known_third_party = "docstring_parser_fork"
multi_line_output = 3
include_trailing_comma = true

Expand Down

0 comments on commit 7ac25ab

Please sign in to comment.