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

Silence B009/B010 for non-identifiers #116

Merged
merged 1 commit into from Jan 29, 2020

Conversation

pkolbus
Copy link
Contributor

@pkolbus pkolbus commented Jan 26, 2020

If an object implements __getattr__ and/or __setattr__, the second parameter to a getattr() or setattr() call might not be a valid Python identifier (e.g. getattr(foo, "123abc")). In this case bugbear should not emit B009/B010, since changing to foo.123abc would be a SyntaxError. Update the B009/B010 detection to check using a regex.

Fixes #113.

If an object implements __getattr__ and/or __setattr__, the second
parameter to getattr() or setattr() may not be a valid Python
identifier (e.g. getattr(foo, "123abc"). In this case bugbear should
not emit B009/B010, since changing to "foo.123abc" would be a
SyntaxError. Update the B009/B010 detection to check using a regex.
@pkolbus pkolbus requested a review from ambv January 26, 2020 18:55
Copy link
Collaborator

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

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

Regex looks legit and tests show this all works.

@cooperlees cooperlees merged commit 7a07a5b into PyCQA:master Jan 29, 2020
@pkolbus
Copy link
Contributor Author

pkolbus commented Jan 29, 2020

Thanks!

@pkolbus pkolbus deleted the b009-b010-improvements branch January 29, 2020 09:11
@cooperlees
Copy link
Collaborator

Thanks for contributing! Appreciate eliminating all false positives!

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.

B009 false positive when attribute is not a keyword
2 participants