Description
Feature
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.