-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add a documentation for simplifiable if expression #6574
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
Add a documentation for simplifiable if expression #6574
Conversation
Pull Request Test Coverage Report for Build 2403335689
π - Coveralls |
54a732e
to
4d11dce
Compare
FLYING_THINGS = ["bird", "plane", "superman", "this example"] | ||
|
||
def is_flying_animal(an_object): | ||
if isinstance(an_object, Animal) and an_object in FLYING_THINGS: |
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.
We need to expect a message here.
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.
Yes, it's not raising anything right now, so I did not expect it to work I think it's a problem and that's why this issue is labelled discussion:
I realized during implementation that simplifiable if expression became worst and that I disagree with #1984 basically. If there are two values but one if the opposite of the other we can pretty much simplify the if expression. It look like the example from the issue come directly from this stackoverflow question but the top answer make a compelling point that this is simplifiable.
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.
Ah okay.
I'm not sure whether I think we should raise here. I'll let others give their opinion as well.
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.
I think #1984 was correct, because even if the two values are given opposing boolean values, we can't simplify, because they might have had state before.
E.g. this raises TypeError
because b
had state:
def x():
a = []
b = []
if bool('special test'):
a = True
else:
b = False
return a + b
But if we refactor to return bool('special test')
, then the behavior is different.
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.
You're right, thank you for your input π I think this is still simplifiable because clearly the code style is horrible (with type redefinition of a and b and the conditional can still be simplified : clearly we don't have this type of construct in the primer π) but it's another MR's scope.
3ef2922
to
4e1c4f2
Compare
c9a78b8
to
9425897
Compare
This comment has been minimized.
This comment has been minimized.
9425897
to
83c3ad3
Compare
83c3ad3
to
87d3988
Compare
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
β¦statement Refs pylint-dev#5953 Closes pylint-dev#5882
87d3988
to
35fe42b
Compare
π€ According to the primer, this change has no effect on the checked open source code. π€π |
Type of Changes
Description
I realized during implementation that simplifiable if expression became worst and that I disagree with #1984 basically. If there are two values but one if the opposite of the other we can pretty much simplify the if expression. It look like the example from the issue come directly from this stackoverflow question but the top answer make a compelling point that this is simplifiable.
Refs #5953
Closes #5882