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

Allow skipping decorated functions #204

Merged
merged 2 commits into from
Oct 16, 2016
Merged

Allow skipping decorated functions #204

merged 2 commits into from
Oct 16, 2016

Conversation

larsoner
Copy link
Contributor

@larsoner larsoner commented Sep 6, 2016

@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.:

--ignore-decorators=wraps

Or in my case, I will add this to my config:

ignore-decorators = copy_.*_doc_to_.*

@larsoner
Copy link
Contributor Author

larsoner commented Sep 6, 2016

If this seems to work, I'm happy to tackle #171 next, since I'll want that, too.

@Nurdok
Copy link
Member

Nurdok commented Oct 13, 2016

Please merge from default, this PR is out of date with the recent refactoring.

@larsoner larsoner force-pushed the skip-dec branch 2 times, most recently from 4594f1d to ed19ba2 Compare October 14, 2016 00:16
@larsoner
Copy link
Contributor Author

@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)
Copy link
Contributor Author

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

Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

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) \
Copy link
Member

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 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use_dafaults -> use_defaults

Copy link
Contributor Author

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,
Copy link
Member

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,
Copy link
Member

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.

Copy link
Contributor Author

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?

@larsoner
Copy link
Contributor Author

Thanks for the review @Nurdok. Rebased after conflicts and then addressed your comments.

@Nurdok Nurdok merged commit ccfafc9 into PyCQA:master Oct 16, 2016
@Nurdok
Copy link
Member

Nurdok commented Oct 16, 2016

Merged. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants