Added `--count` flag. #89

Merged
merged 1 commit into from Jan 3, 2015

Projects

None yet

3 participants

@Nurdok
Member
Nurdok commented Jan 3, 2015

As per #86.

@sigmavirus24 sigmavirus24 commented on the diff Jan 3, 2015
pep257.py
sys.stderr.write('%s\n' % error)
code = 1
+ count += 1
+ if options.count:
+ print(count)
@sigmavirus24
sigmavirus24 Jan 3, 2015 Member

Why not just print(len(errors)) at the end instead of keeping a count variable?

@Nurdok
Nurdok Jan 3, 2015 Member

Because errors is a generator object. I also think this is a bit ugly. I'd love to hear suggestions.

@sigmavirus24
sigmavirus24 Jan 3, 2015 Member

Ah, I forgot errors was a generator. This is fine then.

@Nurdok
Nurdok Jan 3, 2015 Member

In any case, I really appreciate the effort of going through pull requests. Thanks @sigmavirus24!

@sigmavirus24
sigmavirus24 Jan 3, 2015 Member

Always happy to help. As maintainer of flake8-docstrings I think I'll have to account for this new flag in the next release because --count is a flag already offered by pep8. (It's what piqued my interest particularly. :))

@keleshev
keleshev Jan 5, 2015 Contributor

How about:

    errors = check(collected, ignore=options.ignore.split(','))
    count = 0
    for count, error in enumerate(errors, 1):
        sys.stderr.write('%s\n' % error)
    if options.count:
        print(count)
    return int(count != 0)

Current code for comparison:

    errors = check(collected, ignore=options.ignore.split(','))
    code = 0
    count = 0
    for error in errors:
        sys.stderr.write('%s\n' % error)
        code = 1
        count += 1
    if options.count:
        print(count)
    return code
@sigmavirus24
sigmavirus24 Jan 6, 2015 Member

It's simpler, but I'm not sure it's that important of an optimization.

@Nurdok Nurdok merged commit 21bf376 into PyCQA:master Jan 3, 2015

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@Nurdok Nurdok deleted the Nurdok:count branch Jan 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment