pyupgrade icon indicating copy to clipboard operation
pyupgrade copied to clipboard

constant fold isinstance(x, (str, str))

Open graingert opened this issue 4 years ago • 1 comments

input

import ham, value
import six


if isinstance(value, (six.text_type, str)):
    ham()

actual output (with pyupgrade --py38-plus)

import ham, value
import six


if isinstance(value, (str, str)):
    ham()

expected output:

import ham, value
import six


if isinstance(value, str):
    ham()

graingert avatar Jul 27 '21 18:07 graingert

Something similar is done for OSError aliases so perhaps that code can be adapted for this issue too. https://github.com/asottile/pyupgrade/blob/53c94718aae4074edde7099996c81ab7cc081ce3/pyupgrade/_plugins/oserror_aliases.py#L43

mxr avatar Aug 10 '21 04:08 mxr

I'm going to make this work for the tuple case -- the union case is a little more complicated and I'll just leave that notimplemented

asottile avatar Sep 23 '23 19:09 asottile