sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.53k stars 66 forks source link

refactoring issue: merge isinstance calls #274

Closed TheMythologist closed 1 year ago

TheMythologist commented 2 years ago

Checklist

Description

The "merge-isinstance" refactor is incomplete - it only offers the refactoring when two isinstance calls are separated by an or. The refactoring doesn't show up if there are more than two isinstance calls.

a = input()
if isinstance(a, int) or isinstance(a, str):
    print("refactoring suggestion shows up")

if isinstance(a, int) or isinstance(a, str) or isinstance(a, bool):
    print("refactoring suggestion doesn't show up")

Debug Information

IDE Version: Visual Studio Code 1.71.0

Sourcery Version: Sourcery 0.12.7

Operating system and Version: Windows 10 - 10.0.19044 Build 19044

reka commented 2 years ago

Hi, Thanks for reporting this. You're right this refactoring works only with 2 isinstance calls, but it could work for 3 or more isinstance calls as well. We'll probably look into this some time in the autumn.

Some background info We have a similar "2 vs more" topic for some other refactorings as well. :slightly_smiling_face: We've introduced some new syntax to our refactoring DSL, which will enable us to make these refactorings more flexible. The new syntax still needs some cleanup, but afterwards we'll tackle these cases.

Cheers, Reka

Hellebore commented 2 years ago

This should go live with the next release.

Hellebore commented 1 year ago

Noe live with 0.12.8

TheMythologist commented 1 year ago

👍 works, thanks!