MartinThoma / flake8-simplify

❄ A flake8 plugin that helps you to simplify code
MIT License
186 stars 19 forks source link

[Bug] SIM114 reports false positive finding #70

Closed kasium closed 2 years ago

kasium commented 3 years ago

Desired change

Explanation

The current one is wrong 😄

Example

def complicated_calc(*arg, **kwargs):
    return 42

def foo(p):
    if p == 2:
        return complicated_calc(microsecond=0)
    elif p == 3:
        return complicated_calc(microsecond=0, second=0)
    return None
dummy.py:5:8: SIM114 Use logical or ((p == 2) or (p == 3)) and a single body
oliver-sanders commented 3 years ago

Here's another false positive:

a = False      
b = True       
c = True       

if a:          
    z = 1      
elif b:        
    z = 2      
elif c:        
    z = 1 

The a and c branches cannot be merged into a single body because of the b branch inbetween.

noamkush commented 3 years ago

I noticed the buggy behavior happens on Python 3.6 but not on 3.8 (haven't checked 3.7).

MartinThoma commented 3 years ago

@oliver-sanders Uh, good catch! I haven't thought about something like this!

ergoithz commented 2 years ago

Also happening on 3.7.10

MacFan4000 commented 2 years ago

https://github.com/MirahezeBots/sopel-channelmgnt/runs/4704103764?check_suite_focus=true we are running into the same issue.

MartinThoma commented 2 years ago

Fixed in flake8-simplify==0.14.3