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

Commit daeda05

Browse files
committed
Fix documentation and cleaner style
1 parent 8ea53ea commit daeda05

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

docs/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Current Development Version
1010
Major Updates
1111

1212
* Support for Python 2.6 has been dropped (#206, #217).
13+
* Decorator-based skipping via ``--ignore-decorators`` has been added (#204).
1314

1415
1.1.1 - October 4th, 2016
1516
-------------------------

docs/snippets/cli.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ Usage
3636
search only dirs that exactly match <pattern> regular
3737
expression; default is --match-dir='[^\.].*', which
3838
matches all dirs that don't start with a dot
39+
--ignore-decorators=<decorators>
40+
ignore any functions or methods that are decorated by
41+
a function with a name fitting the <decorators>
42+
regular expression; default is --ignore-decorators=''
43+
which does not ignore any decorated functions.
3944
4045
4146
Return Code

src/pydocstyle/checker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from . import violations
1111
from .config import IllegalConfiguration
12-
# TODO: handle
1312
from .parser import (Package, Module, Class, NestedClass, Definition, AllError,
1413
Method, Function, NestedFunction, Parser, StringIO)
1514
from .utils import log, is_blank
@@ -50,10 +49,11 @@ def check_source(self, source, filename, ignore_decorators):
5049
for this_check in self.checks:
5150
terminate = False
5251
if isinstance(definition, this_check._check_for):
53-
if definition.skipped_error_codes != 'all' and \
54-
not any(ignore_decorators is not None and
55-
len(ignore_decorators.findall(dec.name))
56-
for dec in definition.decorators):
52+
skipping_all = (definition.skipped_error_codes == 'all')
53+
decorator_skip = ignore_decorators is not None and any(
54+
len(ignore_decorators.findall(dec.name)) > 0
55+
for dec in definition.decorators)
56+
if not skipping_all and not decorator_skip:
5757
error = this_check(None, definition,
5858
definition.docstring)
5959
else:

src/pydocstyle/config.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def parse(self):
114114

115115
self._run_conf = self._create_run_config(self._options)
116116

117-
config = self._create_check_config(self._options, use_dafaults=False)
117+
config = self._create_check_config(self._options, use_defaults=False)
118118
self._override_by_cli = config
119119

120120
@check_initialized
@@ -141,7 +141,7 @@ def _get_matches(config):
141141
match_dir_func = re(config.match_dir + '$').match
142142
return match_func, match_dir_func
143143

144-
def _get_ignore_dec(config):
144+
def _get_ignore_decorators(config):
145145
"""Return the `ignore_decorators` as None or regex."""
146146
if config.ignore_decorators: # not None and not ''
147147
ignore_decorators = re(config.ignore_decorators)
@@ -154,7 +154,7 @@ def _get_ignore_dec(config):
154154
for root, dirs, filenames in os.walk(name):
155155
config = self._get_config(root)
156156
match, match_dir = _get_matches(config)
157-
ignore_dec = _get_ignore_dec(config)
157+
ignore_decorators = _get_ignore_decorators(config)
158158

159159
# Skip any dirs that do not match match_dir
160160
dirs[:] = [dir for dir in dirs if match_dir(dir)]
@@ -163,13 +163,13 @@ def _get_ignore_dec(config):
163163
if match(filename):
164164
full_path = os.path.join(root, filename)
165165
yield (full_path, list(config.checked_codes),
166-
ignore_dec)
166+
ignore_decorators)
167167
else:
168168
config = self._get_config(name)
169169
match, _ = _get_matches(config)
170-
ignore_dec = _get_ignore_dec(config)
170+
ignore_decorators = _get_ignore_decorators(config)
171171
if match(name):
172-
yield (name, list(config.checked_codes), ignore_dec)
172+
yield (name, list(config.checked_codes), ignore_decorators)
173173

174174
# --------------------------- Private Methods -----------------------------
175175

@@ -313,9 +313,8 @@ def _merge_configuration(self, parent_config, child_options):
313313

314314
kwargs = dict(checked_codes=error_codes)
315315
for key in ('match', 'match_dir', 'ignore_decorators'):
316-
kwargs[key] = getattr(child_options, key) \
317-
if getattr(child_options, key) is not None \
318-
else getattr(parent_config, key)
316+
kwargs[key] = \
317+
getattr(child_options, key) or getattr(parent_config, key)
319318
return CheckConfiguration(**kwargs)
320319

321320
def _parse_args(self, args=None, values=None):
@@ -331,23 +330,23 @@ def _create_run_config(options):
331330
return RunConfiguration(**values)
332331

333332
@classmethod
334-
def _create_check_config(cls, options, use_dafaults=True):
333+
def _create_check_config(cls, options, use_defaults=True):
335334
"""Create a `CheckConfiguration` object from `options`.
336335
337-
If `use_dafaults`, any of the match options that are `None` will
336+
If `use_defaults`, any of the match options that are `None` will
338337
be replaced with their default value and the default convention will be
339338
set for the checked codes.
340339
341340
"""
342341
checked_codes = None
343342

344-
if cls._has_exclusive_option(options) or use_dafaults:
343+
if cls._has_exclusive_option(options) or use_defaults:
345344
checked_codes = cls._get_checked_errors(options)
346345

347346
kwargs = dict(checked_codes=checked_codes)
348347
for key in ('match', 'match_dir', 'ignore_decorators'):
349348
kwargs[key] = getattr(cls, 'DEFAULT_{0}_RE'.format(key.upper())) \
350-
if getattr(options, key) is None and use_dafaults \
349+
if getattr(options, key) is None and use_defaults \
351350
else getattr(options, key)
352351
return CheckConfiguration(**kwargs)
353352

@@ -530,7 +529,7 @@ def _create_option_parser(cls):
530529
help=("ignore any functions or methods that are decorated "
531530
"by a function with a name fitting the <decorators> "
532531
"regular expression; default is --ignore-decorators='{0}'"
533-
"which does not ignore any decorated functions."
532+
" which does not ignore any decorated functions."
534533
.format(cls.DEFAULT_IGNORE_DECORATORS_RE)))
535534
return parser
536535

0 commit comments

Comments
 (0)