Skip to content

Commit fe2bc89

Browse files
author
Ossian O'Reilly
committed
Add examples.
1 parent 8b893bd commit fe2bc89

File tree

6 files changed

+163
-1
lines changed

6 files changed

+163
-1
lines changed

examples/example.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
def example_function(arg1, arg2=1):
2+
"""
3+
This is an example of a docstring that conforms to the Google style guide.
4+
The indentation uses four spaces (no tabs). Note that each section starts
5+
with a header such as `Arguments` or `Returns` and its contents is indented.
6+
7+
Arguments:
8+
9+
arg1 (`int`): This description for this argument fits on one line.
10+
arg2 (`int`, optional): This description is too long to fit on a
11+
single line. Note that it is continued by being indented.
12+
13+
Returns:
14+
15+
`bool` : Stating the return type here is optional.
16+
17+
We can continue putting explanations in this section as long as the text
18+
is indented.
19+
20+
This text is no longer indented and therefore not part of the `Returns`
21+
section.
22+
23+
Raises:
24+
25+
ValueError: This is exception is raised when arg1 and arg2 are equal.
26+
27+
"""
28+
if arg1 == arg2:
29+
raise ValueError("`arg1` and `arg2` cannot be equal.")
30+
if arg1 > arg2:
31+
return True
32+
else:
33+
return False

examples/example.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
docstring examples/example.py example_function --text > examples/example_py.txt
2+
docstring examples/example.py example_function --markdown > examples/example_py.md
3+
docstring examples/example.py example_function --json > examples/example_py.json

examples/example_py.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[
2+
{
3+
"args": [],
4+
"header": "",
5+
"text": "\n\nThis is an example of a docstring that conforms to the Google style guide. \nThe indentation uses four spaces (no tabs). Note that each section starts\nwith a header such as `Arguments` or `Returns` and its contents is indented.\n"
6+
},
7+
{
8+
"args": [
9+
{
10+
"description": "This description for this argument fits on one line.",
11+
"field": "arg1",
12+
"signature": "(`int`)"
13+
},
14+
{
15+
"description": "This description is too long to fit on a\n single line. Note that it is continued by being indented. ",
16+
"field": "arg2",
17+
"signature": "(`int`, optional)"
18+
}
19+
],
20+
"header": "Arguments",
21+
"text": "\n"
22+
},
23+
{
24+
"args": [
25+
{
26+
"description": " Stating the return type here is optional.",
27+
"field": "",
28+
"signature": ""
29+
}
30+
],
31+
"header": "Returns",
32+
"text": "\n\nWe can continue putting explanations in this section as long as the text\nis indented.\n"
33+
},
34+
{
35+
"args": [],
36+
"header": "",
37+
"text": "This text is no longer indented and therefore not part of the `Returns`\nsection.\n"
38+
},
39+
{
40+
"args": [
41+
{
42+
"description": "This is exception is raised when arg1 and arg2 are the same.",
43+
"field": "ValueError",
44+
"signature": ""
45+
}
46+
],
47+
"header": "Raises",
48+
"text": "\n\n"
49+
},
50+
{}
51+
]

examples/example_py.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
# example_function
3+
```python
4+
def example_function(arg1, arg2=1):
5+
```
6+
7+
---
8+
9+
10+
This is an example of a docstring that conforms to the Google style guide.
11+
The indentation uses four spaces (no tabs). Note that each section starts
12+
with a header such as `Arguments` or `Returns` and its contents is indented.
13+
14+
## Arguments
15+
* **arg1** (`int`) : This description for this argument fits on one line.
16+
* **arg2** (`int`, optional) : This description is too long to fit on a
17+
single line. Note that it is continued by being indented.
18+
19+
20+
## Returns
21+
* Stating the return type here is optional.
22+
23+
24+
We can continue putting explanations in this section as long as the text
25+
is indented.
26+
27+
---
28+
This text is no longer indented and therefore not part of the `Returns`
29+
section.
30+
31+
## Raises
32+
* **ValueError** : This is exception is raised when arg1 and arg2 are equal.
33+
34+
35+
36+
37+
## Source
38+
```python
39+
def example_function(arg1, arg2=1):
40+
if arg1 == arg2:
41+
raise ValueError("`arg1` and `arg2` cannot be equal")
42+
if arg1 > arg2:
43+
return True
44+
else:
45+
return False
46+
47+
```
48+

examples/example_py.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
example_function(arg1, arg2=1)
2+
3+
This is an example of a docstring that conforms to the Google style guide.
4+
The indentation uses four spaces (no tabs). Note that each section starts
5+
with a header such as `Arguments` or `Returns` and its contents is indented.
6+
7+
Arguments:
8+
9+
arg1 (`int`): This description for this argument fits on one line.
10+
arg2 (`int`, optional): This description is too long to fit on a
11+
single line. Note that it is continued by being indented.
12+
13+
Returns:
14+
15+
`bool` : Stating the return type here is optional.
16+
17+
We can continue putting explanations in this section as long as the text
18+
is indented.
19+
20+
This text is no longer indented and therefore not part of the `Returns`
21+
section.
22+
23+
Raises:
24+
25+
ValueError: This is exception is raised when arg1 and arg2 are the same.
26+
27+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup
22

33
setup(name='mydocstring',
4-
version='0.1.0',
4+
version='0.1.1',
55
description="""A tool for extracting and converting Google-style docstrings to
66
plain-text, markdown, and JSON.""",
77
url='http://github.com/ooreilly/mydocstring',

0 commit comments

Comments
 (0)