Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Fix remove_class #50

wants to merge 1 commit into from

Conversation

Code0x58
Copy link
Contributor

This is to fix #49

Copy link
Collaborator

@htgoebel htgoebel left a 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

tests/fixtures/remove_class/assertEqual_in.py Outdated Show resolved Hide resolved
pass
if True:
if False:
pass
Copy link
Collaborator

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,
)
Copy link
Collaborator

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]
Copy link
Collaborator

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":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
elif leaf.prefix[:1] in "\r\n":
elif leaf.startswith(("\r", "\n")):

Copy link
Contributor Author

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

Copy link
Collaborator

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?

@Code0x58
Copy link
Contributor Author

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.

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

Successfully merging this pull request may close these issues.

remove_class fix breaks code when there are decorators on methods
3 participants