Feature
Please add a command line and configuration parameter --disable-bytes-alias to avoid Mypy to consider bytes an alias for bytearray and memoryview.
Pitch
In the documentation of typing.ByteString, a little footnote probably, entered by the author's cat walking on the keyboard and entering random keypresses, says that bytes can be used as a shorthand to represent unrelated types such as memoryview, which have a different interface. See #12643.
As a result, it is not possible to obtain reliable code analysis on code using different ByteString types, such as:
def f(data: ByteString) -> str:
if not isinstance(data, bytes):
data = bytes(data)
return data.decode()
Mypy will report that the if branch will never be executed, then it will proceed to complain that memoryview doesn't have a decode() method.
It would be nice to have this behaviour deprecated and eventually removed and forgotten (no harm intended to the cat). However, as this is a long process, it would be nice to give developers the possibility to disable this ill-thought rule sooner.
Feature
Please add a command line and configuration parameter
--disable-bytes-aliasto avoid Mypy to considerbytesan alias forbytearrayandmemoryview.Pitch
In the documentation of
typing.ByteString, a little footnote probably, entered by the author's cat walking on the keyboard and entering random keypresses, says thatbytescan be used as a shorthand to represent unrelated types such asmemoryview, which have a different interface. See #12643.As a result, it is not possible to obtain reliable code analysis on code using different
ByteStringtypes, such as:Mypy will report that the
ifbranch will never be executed, then it will proceed to complain thatmemoryviewdoesn't have adecode()method.It would be nice to have this behaviour deprecated and eventually removed and forgotten (no harm intended to the cat). However, as this is a long process, it would be nice to give developers the possibility to disable this ill-thought rule sooner.