Description
Every once in a while we change something in mypy that breaks backward compatibility, and this can make it hard for owners of large codebases to migrate to a new mypy version. A related issue is that some changes that we'd like to make would cause so much work for existing users that we decide to postpone the change indefinitely (see #5392 as an example).
What if we'd adopt a policy of retaining the old behaviors through a configuration option, whenever there is a lot of expected breakage? This way existing users could just continue to use the old behavior without having to migrate their code, while new users would automatically get the new (and improved, I'd hope) behavior.
A potential drawback would be the introduction of many additional options for legacy behaviors that are only of interest to a small subset of users. My solution to this is to enable all of the behaviors with a single option.
Let's use #5392 as an example. The change would cause some if/else expression to return a union type instead of a join. We could enable the old behavior through --backward-compat if-else
(the option name needs more thought). The value of the option would be a comma-separated list of legacy behaviors.
Another candidate for this feature is #5401.
Pros:
- Migration to new mypy versions will be easier for users with lots of code.
- Breaking changes are easier to justify, since we can provide a fallback for existing users.
- Backward compatibility features are behind a single option which can be easily ignored by users that don't care about it.
- If the compatibility options are per-module, migration to new semantics can be performed gradually.
Cons:
- Some users may be unaware of the option and be reluctant to upgrade to new mypy versions because of the migration work they believe to be necessary.
- Supporting multiple additional options may decrease maintainability of mypy and result in bugs and weird corner cases.
- We may never be able to deprecate some old behaviors.