Skip to content

Commit 9abad26

Browse files
committed
fix issue where passing two styles would fail with index error
1 parent 60a82b3 commit 9abad26

File tree

4 files changed

+140
-1
lines changed

4 files changed

+140
-1
lines changed

pydocstringformatter/_formatting/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def treat_string(
278278
if first_section:
279279
section[0] = section[0].lstrip()
280280
first_section = False
281-
elif not section[0][0].isspace():
281+
elif len(section[0]) > 0 and not section[0][0].isspace():
282282
section[0] = f"{' ' * indent_length:s}{section[0]:s}"
283283

284284
# Rejoin sections
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--style=numpydoc
2+
--style=pep257
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""Example module for numpydoc docstring style.
2+
References
3+
-----
4+
NumPy docstring style guide:
5+
https://numpydoc.readthedocs.io/en/latest/format.html#documenting-modules"""
6+
import math
7+
8+
EULER_NUMBER = math.e
9+
"""Euler's number.
10+
11+
Not related to Euler's constant (sometimes called the Euler-Mascheroni
12+
constant.
13+
References
14+
-----
15+
E (mathematical constant)
16+
https://en.wikipedia.org/wiki/E_(mathematical_constant)
17+
Notes
18+
---
19+
It is the limit of ``(1 + 1/n)**n`` as n approaches infinity, so it
20+
is used in the equation for continuously-compouned interest.
21+
22+
It is also the sum of the reciprocals of the whole numbers starting
23+
with zero, which is related to some calculus-related properties
24+
mathemeticians find elegant.
25+
"""
26+
27+
28+
def sincos(theta):
29+
"""Returns
30+
----
31+
sin: float
32+
the sine of theta
33+
cos: float
34+
the cosine of theta
35+
Raises
36+
---
37+
TypeError
38+
If `theta` is not a float.
39+
Parameters
40+
-----
41+
theta: float
42+
the angle at which to calculate the sine and cosine.
43+
"""
44+
return math.sin(theta), math.cos(theta)
45+
46+
47+
def fibbonacci():
48+
"""Generate the Fibonacci sequence.
49+
50+
Each term is the sum of the two previous; conventionally starts
51+
with two ones.
52+
References
53+
-----
54+
Fibonacci numbers
55+
https://en.wikipedia.org/wiki/Fibonacci_number
56+
Yields
57+
---
58+
int"""
59+
curr = 1
60+
last = 0
61+
while True:
62+
yield curr
63+
curr, last = curr + last, curr
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""Example module for numpydoc docstring style.
2+
3+
References
4+
----------
5+
NumPy docstring style guide:
6+
https://numpydoc.readthedocs.io/en/latest/format.html#documenting-modules
7+
"""
8+
import math
9+
10+
EULER_NUMBER = math.e
11+
"""Euler's number.
12+
13+
Not related to Euler's constant (sometimes called the Euler-Mascheroni
14+
constant.
15+
16+
Notes
17+
-----
18+
It is the limit of ``(1 + 1/n)**n`` as n approaches infinity, so it
19+
is used in the equation for continuously-compouned interest.
20+
21+
It is also the sum of the reciprocals of the whole numbers starting
22+
with zero, which is related to some calculus-related properties
23+
mathemeticians find elegant.
24+
25+
References
26+
----------
27+
E (mathematical constant)
28+
https://en.wikipedia.org/wiki/E_(mathematical_constant)
29+
"""
30+
31+
32+
def sincos(theta):
33+
"""Returns.
34+
35+
Parameters
36+
----------
37+
theta : float
38+
the angle at which to calculate the sine and cosine.
39+
40+
Raises
41+
------
42+
TypeError
43+
If `theta` is not a float.
44+
45+
46+
47+
sin: float
48+
the sine of theta
49+
cos: float
50+
the cosine of theta
51+
"""
52+
return math.sin(theta), math.cos(theta)
53+
54+
55+
def fibbonacci():
56+
"""Generate the Fibonacci sequence.
57+
58+
Each term is the sum of the two previous; conventionally starts
59+
with two ones.
60+
61+
Yields
62+
------
63+
int
64+
65+
References
66+
----------
67+
Fibonacci numbers
68+
https://en.wikipedia.org/wiki/Fibonacci_number
69+
"""
70+
curr = 1
71+
last = 0
72+
while True:
73+
yield curr
74+
curr, last = curr + last, curr

0 commit comments

Comments
 (0)