Skip to content

Commit 5a56060

Browse files
committed
Fix regex to deal with mixing of quotes at start of string
1 parent 27de0df commit 5a56060

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

pydocstringformatter/_formatting/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def treat_token(self, tokeninfo: tokenize.TokenInfo) -> tokenize.TokenInfo:
7373
class StringAndQuotesFormatter(Formatter):
7474
"""Base class for string formatter that needs access to the quotes."""
7575

76-
quotes_regex = re.compile(r"""['"]{1,3}""")
76+
quotes_regex = re.compile(r"""^('{3}|'|"{3}|")""")
7777
"""Pattern to match against opening quotes."""
7878

7979
@abc.abstractmethod
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def a(self):
2+
"'a.m.' or 'p.m.'"
3+
4+
def b(self):
5+
"""'a.m.' or 'p.m.'"""
6+
7+
def c(self):
8+
"'''a.m.''' or 'p.m.'"
9+
10+
def d(self):
11+
"""'''a.m.''' or 'p.m.'"""
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def a(self):
2+
"""'A.m.' or 'p.m.'."""
3+
4+
def b(self):
5+
"""'a.m.' or 'p.m.'."""
6+
7+
def c(self):
8+
"""'''a.m.''' or 'p.m.'."""
9+
10+
def d(self):
11+
"""'''a.m.''' or 'p.m.'."""
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def a(self):
2+
'"a.m." or "p.m."'
3+
4+
def b(self):
5+
'''"a.m." or "p.m."'''
6+
7+
def c(self):
8+
'"""a.m.""" or "p.m."'
9+
10+
def d(self):
11+
'''"""a.m.""" or "p.m."'''
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def a(self):
2+
""""A.m." or "p.m."."""
3+
4+
def b(self):
5+
""""a.m." or "p.m."."""
6+
7+
def c(self):
8+
""""""a.m.""" or "p.m."."""
9+
10+
def d(self):
11+
""""""a.m.""" or "p.m."."""

0 commit comments

Comments
 (0)