Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 96092cd

Browse files
blueyedNurdok
authored andcommitted
Strip whitespace in _fix_set_options (#431)
This allows to specify e.g. "ignore" on multiple lines, without adding additional commas: [pydocstyle] ignore = D100,D101,D102,D103, # "1 blank line required before class docstring" # Disabled by default, conflicts with D211. D203, # "Multi-line docstring summary should start at the second line" (vs. D212). D213,
1 parent d3ea9a0 commit 96092cd

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

docs/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ New Features
1919
docstrings (#407).
2020
* Added support for Python 3.8 (#423).
2121
* Allow skipping errors on module level docstring via #noqa (#427).
22+
* Whitespace is ignored with set options split across multiple lines (#221).
2223

2324
Bug Fixes
2425

src/pydocstyle/config.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,14 @@ def _fix_set_options(cls, options):
515515
def _get_set(value_str):
516516
"""Split `value_str` by the delimiter `,` and return a set.
517517
518-
Removes any occurrences of '' in the set.
519-
Also expand error code prefixes, to avoid doing this for every
518+
Removes empty values ('') and strips whitespace.
519+
Also expands error code prefixes, to avoid doing this for every
520520
file.
521521
522522
"""
523-
return cls._expand_error_codes(set(value_str.split(',')) - {''})
523+
return cls._expand_error_codes(
524+
set([x.strip() for x in value_str.split(",")]) - {""}
525+
)
524526

525527
for opt in optional_set_options:
526528
value = getattr(options, opt)

src/tests/test_integration.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,16 @@ def foo():
446446
assert 'D300' not in out
447447

448448

449+
def test_ignores_whitespace_in_fixed_option_set(env):
450+
with env.open('example.py', 'wt') as example:
451+
example.write("class Foo(object):\n 'Doc string'")
452+
env.write_config(ignore="D100,\n # comment\n D300")
453+
out, err, code = env.invoke()
454+
assert code == 1
455+
assert 'D300' not in out
456+
assert err == ''
457+
458+
449459
def test_bad_wildcard_add_ignore_cli(env):
450460
"""Test adding a non-existent error codes with --add-ignore."""
451461
with env.open('example.py', 'wt') as example:

0 commit comments

Comments
 (0)