DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
https://docs.basedpyright.com
Other
863 stars 16 forks source link

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

Open ItsDrike opened 1 month ago

ItsDrike commented 1 month ago

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).

DetachHead commented 1 month ago

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