-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix remove_class #50
Fix remove_class #50
Conversation
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.
Thansk for this pull-request. I added some inline-comments.
Alos pelase change the commitmessage into something like: "fix indent for decorators on methods".
Thanks
pass | ||
if True: | ||
if False: | ||
pass |
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.
Why this doc-string and this code? Is it to test dedenting? So please add a brief comment above.
( | ||
1, | ||
2, | ||
) |
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.
Same here: Why this fancy, non-PEP-8 formattted code?
break | ||
else: | ||
i = len(s) | ||
return s[:i] + s[i:-dedent] |
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.
Plese add a breif comment what this does
leaf.prefix = safe_dedent(leaf.prefix) | ||
elif leaf.type == token.INDENT: | ||
leaf.value = leaf.value[:-dedent] | ||
elif leaf.prefix[:1] in "\r\n": |
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.
elif leaf.prefix[:1] in "\r\n": | |
elif leaf.startswith(("\r", "\n")): |
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.
both are safe, and it turns out the second form is ~50% slower:
$ python -m timeit '""[:1] in "ab"'
5000000 loops, best of 5: 48.6 nsec per loop
$ python -m timeit '"".startswith(("a", "b"))'
5000000 loops, best of 5: 70.5 nsec per loop
$ python -m timeit '"b"[:1] in "ab"'
5000000 loops, best of 5: 49.8 nsec per loop
$ python -m timeit '"b".startswith(("a", "b"))'
5000000 loops, best of 5: 77.8 nsec per loop
$ python -m timeit --setup="s = 'x'*1000" 's[:1] in "ab'
5000000 loops, best of 5: 48.4 nsec per loop
$ python -m timeit --setup="s = 'x'*1000" 's.startswith(("a", "b"))'
5000000 loops, best of 5: 75.7 nsec per loop
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.
Anyhow, the later form is much more easy to understand. And there is not need to optimize for speed in this project, isn't it?
Thanks for the review, I amended with changes. Previously I put in too many cases while trying to understand show things were tokenised, so now they've been simplified and moved to their own fixture. |
This is to fix #49