-
Notifications
You must be signed in to change notification settings - Fork 187
Conversation
If this seems to work, I'm happy to tackle #171 next, since I'll want that, too. |
Please merge from default, this PR is out of date with the recent refactoring. |
4594f1d
to
ed19ba2
Compare
@Nurdok merge wasn't possible because of how bad the split was, but I started fresh and manually copied the changes into the necessary places. Tests pass locallay and Travis is happy. |
@@ -10,7 +10,8 @@ | |||
from . import violations | |||
from .config import IllegalConfiguration | |||
# TODO: handle | |||
from .parser import * | |||
from .parser import (Package, Module, Class, NestedClass, Definition, AllError, | |||
Method, Function, NestedFunction, Parser, StringIO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one wasn't strictly necessary (orthogonal to this PR, maybe violates style prefs?) but it made it a lot easier to make changes because the automated pyflakes
checking works much better without any *
imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great actually - you can remove the "TODO" comment as this is what it meant, forgot to address it when I was refactoring.
if definition.skipped_error_codes != 'all' and \ | ||
not any(ignore_decorators is not None and | ||
len(ignore_decorators.findall(dec.name)) | ||
for dec in definition.decorators): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if
is too long. Break it up by assigning to local variables, something like:
checking_for_errors = ..
skipping_decorator = ..
if checking_for_errors and not skipping_decorator:
# run the check
Think about better names, though :)
@@ -139,31 +141,42 @@ def _get_matches(config): | |||
match_dir_func = re(config.match_dir + '$').match | |||
return match_func, match_dir_func | |||
|
|||
def _get_ignore_dec(config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer if you use the full word decorator
, as this is not a common shorthand (like func
).
match_dir=match_dir) | ||
kwargs = dict(checked_codes=error_codes) | ||
for key in ('match', 'match_dir', 'ignore_decorators'): | ||
kwargs[key] = getattr(child_options, key) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do:
kwargs[key] = getattr(child_options, key) or getattr(parent_config, key)
kwargs = dict(checked_codes=checked_codes) | ||
for key in ('match', 'match_dir', 'ignore_decorators'): | ||
kwargs[key] = getattr(cls, 'DEFAULT_{0}_RE'.format(key.upper())) \ | ||
if getattr(options, key) is None and use_dafaults \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use_dafaults
-> use_defaults
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured that was done intentionally previously for some reason. Happy to change it though.
@@ -518,12 +525,20 @@ def _create_option_parser(cls): | |||
"matches all dirs that don't start with " | |||
"a dot").format(cls.DEFAULT_MATCH_DIR_RE)) | |||
|
|||
# Decorators | |||
option('--ignore-decorators', metavar='<decorators>', default=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to update the docs in both the CLI section and the release notes.
@@ -518,12 +525,20 @@ def _create_option_parser(cls): | |||
"matches all dirs that don't start with " | |||
"a dot").format(cls.DEFAULT_MATCH_DIR_RE)) | |||
|
|||
# Decorators | |||
option('--ignore-decorators', metavar='<decorators>', default=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, should there be special handling of "qualified" decorators? e.g., @wraps
vs @functools.wraps
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can be dealt with via regex
, right?
Thanks for the review @Nurdok. Rebased after conflicts and then addressed your comments. |
Merged. Thanks! |
@Nurdok I think you talked about adding an option like this, see if it's what you have in mind. A user can now do e.g.:
Or in my case, I will add this to my config: