python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.5k stars 2.83k forks source link

Provide an easy way to opt out of changes to default options #17989

Open JukkaL opened 4 weeks ago

JukkaL commented 4 weeks ago

We are planning to change the defaults of some options in mypy 2.0, and it's likely that we'll have more such changes in mypy 3.0 and so on. Some of these require work from many users, for example if we enable a check by default that generates lots of errors (even if they are mostly correct).

Here are some things we might want to change the future:

I think we could provide a way to freeze options to the current level, so that users wouldn't need to touch their config files (or fix issues) on each major feature release. For example, --defaults=1.x could tell mypy to use the defaults mypy versions 1.x use. This could also be set in the config file.

This would make it easier for us to make changes to defaults, and easier for users to adopt these changes at their own pace, while still getting access to new Python versions and new mypy features.

TeamSpen210 commented 4 weeks ago

Maybe this could be described as a minimum mypy version, intended to be set in the config file. mypy would refuse to run if it's older than the specified version, or if mypy dropped support for that version of defaults later on.

JukkaL commented 4 weeks ago

Maybe this could be described as a minimum mypy version

This wouldn't properly address this use case. The feature proposed here would be used to preserve compatibility across major feature releases only, and literally the only possible values would likely be 1.x, 2.x and so on (not e.g. 2.4). And backward compatible changes are possible within minor feature releases (e.g. stub changes), as long as the impact is small enough.

But we could refuse to target the defaults of an old version if we drop support for certain defaults. Usually the goal would be to support the legacy flags indefinitely, or at least over several major releases.