dosisod / refurb

A tool for refurbishing and modernizing Python codebases
GNU General Public License v3.0
2.48k stars 54 forks source link

[Enhancement]: opinions on `isinstance` with `tuple` or union (`|`)? #345

Open jamesbraza opened 2 months ago

jamesbraza commented 2 months ago

Overview

It turns out with Python 3.10+ that isinstance (docs) supports union syntax:

isinstance(5, (int, str))
isinstance(5, int | str)  # New in Python 3.10

Proposal

Actually I think union syntax is pretty slick, and easier to read. I think it would be a cool refurb rule to suggest this refactor.

What do you think?