diff options
| author | Eli Schwartz <eschwartz93@gmail.com> | 2025-09-21 01:41:06 -0400 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2025-09-25 12:58:43 -0400 |
| commit | ee0a1c6b5bb7c42096cf6ea088865dd841dec438 (patch) | |
| tree | 8272b36087f4f2c9b0eab90966bee0f5978826a2 /docs | |
| parent | 6cb9d898ebb5d0f1d619d4937b1c316400802609 (diff) | |
| download | meson-ee0a1c6b5bb7c42096cf6ea088865dd841dec438.tar.gz | |
mypy: enable allow-redefinition-new and fix fallout
Reduces 3 errors that show up in newer mypy versions than pinned in CI.
It is new since 1.16 and a likely future default for mypy 2.0. It allows
things like:
```
for i in ['one', 'two', 'three']:
frob_a(i)
for i in [1, 2, 3]:
frob_b(i)
```
since "i" is obviously used as a loop holder and its type can be freely
reinvented. Note: allow-redefinition-new isn't actually about this at
all, it has greater scope than loop holders and allows redefining
"unannotated variables" of all kinds. No granularity in what to accept
redefinition of. :P
To enable this, we must also opt in to local-partial-types, which has
some overlap with None-safety. Specifically:
> the most common cases for partial types are variables initialized
> using None, but without explicit X | None annotations. By default, mypy
> won’t check partial types spanning module top level or class top level.
> This flag changes the behavior to only allow partial types at local
> level, therefore it disallows inferring variable type for None from two
> assignments in different scopes.
So with this, we also fix a couple of actual type errors this revealed.
Where possible, stop None-initializing at all -- it's not strictly
needed for global variables, anyway, and it's a coding error if it is
possible to hit these variables without defining them first.
Bug: https://github.com/python/mypy/issues/19280
Diffstat (limited to 'docs')
0 files changed, 0 insertions, 0 deletions
