Closed pavel-wmt closed 2 weeks ago
Pyright's behavior here is correct here, so this isn't a bug.
Traditionally, bytes
has been treated as a "promotion type". When used in a type annotation, bytes
implies the union bytes | bytearray | memoryview
. This is similar to float
implying the type float | int
. PEP 688 deprecated bytes
as a promotion type, but existing code bases still rely on this behavior, so pyright honors it by default. If you don't want this behavior, you can set disableBytesTypePromotions
to true in your config file. This will eventually become the default setting.
It has been more than two years since PEP 688 was accepted, so I think it's reasonable at this point to change the default for disableBytesTypePromotions
from false
to true
. This will be included in the next release of pyright.
Describe the bug
bytes | str
incorrectly interpreted asbytes | bytearray | memoryview[_I@memoryview] | str
Code or Screenshots This should type check
But it produces error:
VS Code extension or command-line
pyright 1.1.377