You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We currently have the undocumented flags --disable-bytearray-promotion and --disable-memoryview-promotion that turn off promotions from bytearray/memoryview to bytes. These are a bit unwieldy, and I'm proposing that we add a new flag called --strict-bytes that enables both of these flags, and make it an officially documented feature. In mypy 2.0 we'd switch --strict-bytes on by default.
Additional details:
This should be documented.
Also support --no-strict-bytes for the inverse. This allows users to prepare for mypy 2.0 even if they aren't ready to turn on the flag.
This probably shouldn't be a per-module option, since migration to the new behavior appears to be fairly easy even for large codebases.
We'll still keep the old undocumented flags for now, but they might be removed in the future.
Pitch
Currently bytearray and memoryview are assignable to bytes, which is incorrect, but this has been tricky to fix mostly due to stub quality. Stubs seem to have improved enough for this to be practical now -- any anyway switching the default would give more incentives to fix stubs.
The new flag is shorter and easier to remember, and it combines both of the features so it's simpler. The naming is also arguably consistent with --strict-equality and friends. In my experience dropping the memoryview promotion rarely causes trouble, so having it as a separate flag doesn't seem important.
The text was updated successfully, but these errors were encountered:
Anybody want to work on this? We'd probably need a feature release with this available before we can release mypy 2.0, due to our backward compatibility policy.
hamdanal
added a commit
to hamdanal/mypy
that referenced
this issue
Dec 7, 2024
Feature
We currently have the undocumented flags
--disable-bytearray-promotion
and--disable-memoryview-promotion
that turn off promotions frombytearray
/memoryview
tobytes
. These are a bit unwieldy, and I'm proposing that we add a new flag called--strict-bytes
that enables both of these flags, and make it an officially documented feature. In mypy 2.0 we'd switch--strict-bytes
on by default.Additional details:
--no-strict-bytes
for the inverse. This allows users to prepare for mypy 2.0 even if they aren't ready to turn on the flag.Pitch
Currently
bytearray
andmemoryview
are assignable tobytes
, which is incorrect, but this has been tricky to fix mostly due to stub quality. Stubs seem to have improved enough for this to be practical now -- any anyway switching the default would give more incentives to fix stubs.The new flag is shorter and easier to remember, and it combines both of the features so it's simpler. The naming is also arguably consistent with
--strict-equality
and friends. In my experience dropping thememoryview
promotion rarely causes trouble, so having it as a separate flag doesn't seem important.The text was updated successfully, but these errors were encountered: