basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

unnecessaryIsInstance not reported for bytes type on bytearray | bytes when disableBytesTypePromotions = false

Open ItsDrike opened this issue 1 year ago • 1 comments

For some reason, when disableBytesTypePromotions = false, basedpyright no longer reports unnecessaryIsInstance in the code below:

x: bytes = ...  # pyright: ignore[reportAssignmentType]

if isinstance(x, (bytearray, bytes)):  # problematic line
    ...

Yet with the disableBytesTypePromotions = true, the error is reported properly.

The disableBytesTypePromotions just controles whether or not bytes are considered a supertype of bytearray and memoryview, however, this setting shouldn't matter here, as bytes will always be a subtype of bytes | bytearray, the check should be unnecessary in both cases (unless I'm missing something).

ItsDrike avatar Jul 12 '24 14:07 ItsDrike

i guess whatever special casing pyright does to support this legacy behavior doesn't work properly with reportUnnecessaryIsInstance. tbh i would consider fixing this to be low priority considering this functionality is deprecated and will probably be removed from pyright eventually.

on a related note, i also intend to add an option to disable other type promotions (#319) because i think it's a really dumb feature in general

DetachHead avatar Jul 13 '24 07:07 DetachHead