-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement B028 rule from bugbear #1893
Comments
Hmm okay now that I am looking at it with a closer look though I think this rule may not be as smart as its definition makes it out to be. Take the following code for example: class Person:
def __init__(self, name: str, age: int) -> None:
self.name = name
self.age = age
def __str__(self) -> str:
return f'{self.name} who is {self.age} years old'
def __repr__(self) -> str:
return f'{id(self)}'
john = Person('John', 24)
print(f'"{john}"')
print(f'{john!r}') Since
Running flake8 with that bugbear rule active still seems to advice to change it:
And doing so would be a bug. I wonder if it would be possible to only make it warn you if str == repr for the variable in question. |
@LefterisJP interesting test case, even numeric types have a problem - see PyCQA/flake8-bugbear#329 and also PyCQA/flake8-bugbear#332 - it looks likely the B028 check will be disabled by default |
Yeah I think this rule may not be a good idea at all. I will leave it to @charliermarsh to decide but feel free to close. |
Ah yeah, ok, looks like it's being renamed to B907, so lets close for now. |
flake8-bugbear just released an update to add an interesting rule: https://pypi.org/project/flake8-bugbear/
It hits in some places in rotki's codebase but I am not gonna go change them all manually 😄
It would be great if ruff also detects it and auto-fixes it.
The text was updated successfully, but these errors were encountered: