Avoid erroneous Q002 error message for single-quote docstrings (#1777)

Fixes #1775. Before implementing your solution I thought of a slightly
simpler one. However, it will let this function pass:
```
def double_inside_single(a):
    'Double inside "single "'
```
If we want function to pass, my implementation works. But if we do not,
then I can go with how you suggested I implemented this (I left how I
would begin to handle it commented out). The bottom of the flake8-quotes
documentation seems to suggest that this should pass:
https://pypi.org/project/flake8-quotes/

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This commit is contained in:
Colin Delahunty 2023-01-11 20:01:54 -05:00 committed by GitHub
parent 588399e415
commit 329946f162
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 11 deletions

View file

@ -17,6 +17,15 @@ def fun_with_params_no_docstring(a, b="""
""" """docstring"""): """ """docstring"""):
pass pass
def fun_with_params_no_docstring2(a, b=c[foo():], c=\ def fun_with_params_no_docstring2(a, b=c[foo():], c=\
""" not a docstring """): """ not a docstring """):
pass pass
def function_with_single_docstring(a):
"Single line docstring"
def double_inside_single(a):
'Double inside "single "'

View file

@ -13,11 +13,19 @@ def foo2():
def fun_with_params_no_docstring(a, b=''' def fun_with_params_no_docstring(a, b='''
not a not a
''' '''docstring'''): ''' '''docstring'''):
pass pass
def fun_with_params_no_docstring2(a, b=c[foo():], c=\ def fun_with_params_no_docstring2(a, b=c[foo():], c=\
''' not a docstring '''): ''' not a docstring '''):
pass pass
def function_with_single_docstring(a):
'Single line docstring'
def double_inside_single(a):
"Double inside 'single '"

View file

@ -36,8 +36,8 @@ fn good_multiline_ending(quote: &Quote) -> &str {
fn good_docstring(quote: &Quote) -> &str { fn good_docstring(quote: &Quote) -> &str {
match quote { match quote {
Quote::Single => "'''", Quote::Single => "'",
Quote::Double => "\"\"\"", Quote::Double => "\"",
} }
} }

View file

@ -1,6 +1,6 @@
--- ---
source: src/flake8_quotes/mod.rs source: src/flake8_quotes/mod.rs
expression: checks expression: diagnostics
--- ---
- kind: - kind:
BadQuotesMultilineString: single BadQuotesMultilineString: single
@ -45,10 +45,10 @@ expression: checks
- kind: - kind:
BadQuotesMultilineString: single BadQuotesMultilineString: single
location: location:
row: 21 row: 22
column: 4 column: 4
end_location: end_location:
row: 21 row: 22
column: 27 column: 27
fix: ~ fix: ~
parent: ~ parent: ~

View file

@ -1,6 +1,6 @@
--- ---
source: src/flake8_quotes/mod.rs source: src/flake8_quotes/mod.rs
expression: checks expression: diagnostics
--- ---
- kind: - kind:
BadQuotesDocstring: double BadQuotesDocstring: double
@ -22,4 +22,14 @@ expression: checks
column: 7 column: 7
fix: ~ fix: ~
parent: ~ parent: ~
- kind:
BadQuotesDocstring: double
location:
row: 27
column: 4
end_location:
row: 27
column: 27
fix: ~
parent: ~

View file

@ -1,6 +1,6 @@
--- ---
source: src/flake8_quotes/mod.rs source: src/flake8_quotes/mod.rs
expression: checks expression: diagnostics
--- ---
- kind: - kind:
BadQuotesDocstring: single BadQuotesDocstring: single
@ -22,4 +22,14 @@ expression: checks
column: 7 column: 7
fix: ~ fix: ~
parent: ~ parent: ~
- kind:
BadQuotesDocstring: single
location:
row: 27
column: 4
end_location:
row: 27
column: 27
fix: ~
parent: ~

View file

@ -1,6 +1,6 @@
--- ---
source: src/flake8_quotes/mod.rs source: src/flake8_quotes/mod.rs
expression: checks expression: diagnostics
--- ---
- kind: - kind:
BadQuotesMultilineString: double BadQuotesMultilineString: double
@ -45,10 +45,10 @@ expression: checks
- kind: - kind:
BadQuotesMultilineString: double BadQuotesMultilineString: double
location: location:
row: 21 row: 22
column: 4 column: 4
end_location: end_location:
row: 21 row: 22
column: 27 column: 27
fix: ~ fix: ~
parent: ~ parent: ~