Skip to content

Create a docstring enum #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pydocstring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@

import parso
from parso.python.tree import BaseNode, search_ancestor
from strenum import StrEnum

import pydocstring.formatter
from pydocstring import exc

class DocstringStyle(StrEnum):
GOOGLE = "google"
NUMPY = "numpy"
REST = "reST"

@classmethod
def list_values(cls):
return [x.value for x in cls]


FORMATTER = {
"google": {
DocstringStyle.GOOGLE: {
"start_args_block": "\n\nArgs:\n",
"param_placeholder": " {0} ({1}): {2}\n",
"param_placeholder_args": " *{0}: {1}\n",
Expand All @@ -27,7 +38,7 @@
"start_attributes": "\n\nAttributes:\n",
"attribute_placeholder": " {0} ({1}): {2}\n",
},
"numpy": {
DocstringStyle.NUMPY: {
"start_args_block": "\n\n Parameters\n ----------\n",
"param_placeholder": " {0} : {1}\n {2}\n",
"param_placeholder_args": " *{0}\n {1}\n",
Expand All @@ -42,7 +53,7 @@
"start_attributes": "\n\n Attributes\n ----------\n",
"attribute_placeholder": " {0} : {1}\n {2}\n",
},
"reST": {
DocstringStyle.REST: {
"start_args_block": "\n\n",
"param_placeholder": ":param {0}: {2}\n:type {0}: {1}\n",
"param_placeholder_args": ":param *{0}: {1}\n",
Expand All @@ -60,7 +71,7 @@
}


def generate_docstring(source, position=(1, 0), formatter="google", autocomplete=False):
def generate_docstring(source: str, position=(1, 0), formatter=DocstringStyle.GOOGLE, autocomplete=False):
"""Generate a docstring

Args:
Expand Down
6 changes: 3 additions & 3 deletions pydocstring/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import argparse # pragma: no cover
import ast # pragma: no cover
import pydocstring # pragma: no cover
from pydocstring import exc # pragma: no cover
from pydocstring import DocstringStyle # pragma: no cover


def main(): # pragma: no cover
Expand All @@ -54,8 +54,8 @@ def main(): # pragma: no cover
parser.add_argument(
"-f",
"--formatter",
choices=["google", "numpy", "reST"],
default="google",
choices=DocstringStyle.list_values(),
default=DocstringStyle.GOOGLE,
type=str,
help="docstring formatter to use",
)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
],
},
install_requires=[
'parso>=0.1.1'
'parso>=0.1.1',
'strenum>=0.4.0'
]
)