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

B018: Find more constants w/o assign #201

Merged
merged 1 commit into from Oct 29, 2021
Merged

Conversation

kasium
Copy link
Contributor

@kasium kasium commented Oct 29, 2021

This check now also finds:

  • numbers (ints, float, complex)
  • lists
  • sets
  • dicts
  • binary strings
  • joined strings (f-strings)
  • name constants (True, False, None)

This is part 1 of #200 . The second part will enable the check for modules

This check now also finds:
* numbers (ints, float, complex)
* lists
* sets
* dicts
* binary strings
* joined strings (f-strings)
* name constants (True, False, None)
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.

SGTM - This makes b018 much more complete. Thanks for the efforts. /me wonders how many weird typos across the world this will pickup.

I'll look to release over the weekend / Monday (west coast USA) time ...

@cooperlees cooperlees merged commit 2ca8d79 into PyCQA:master Oct 29, 2021
@kasium kasium deleted the issue-200-1 branch November 2, 2021 07:30
@asottile
Copy link
Member

I think this still misses a few things, such as this subtle bug:

def f():
    f"string"

@kasium
Copy link
Contributor Author

kasium commented Nov 15, 2021

@asottile thanks for your feedback. If I'm not wrong, JoinedStr is catched:
https://github.com/PyCQA/flake8-bugbear/blob/master/bugbear.py#L589

And a f-string w/o parameter is catched in pyflakes I guess

@asottile
Copy link
Member

it's only caught at body positions 1+

@kasium
Copy link
Contributor Author

kasium commented Nov 15, 2021

Ah, yes. You are right.

However, I'm not sure if this should be covered here. It's not recommended to use " as the docstring and to find out which quotes where used, I guess tokens are needed. Therefore, I see this more in https://pypi.org/project/flake8-docstrings/.

@cooperlees what do you think?

@asottile
Copy link
Member

no all I'm suggesting is to extend the check to 0+ instead of 1+ and add an exception for Str at 0

@kasium
Copy link
Contributor Author

kasium commented Nov 15, 2021

Sorry, that was clear 😄. Let me open a PR. That's a great idea!

@kasium kasium mentioned this pull request Nov 15, 2021
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.

None yet

3 participants