Fix slots issue with deferred base - #20573
Conversation
Fixes python#17121 Generated by codex
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
| slots_defined_by_plugin = existing_slots is not None and existing_slots.plugin_generated | ||
| if existing_slots is not None and not slots_defined_by_plugin: |
There was a problem hiding this comment.
I don't really get how the original was wrong. Like why is info.slots a thing (or __slots__ in info.names?)... And why do we have to care about it being plugin generated, is this plugin being run multiple times? (I see the old code had info.slots != generated_slots for this too. That seems odd)
There was a problem hiding this comment.
Yes, I think the deferral led to this being called multiple times
There was a problem hiding this comment.
Oh I see, if this is run multiple times then __slots__ will be added then trigger this if statement (in the old code). Is there a reason we can't store "we've processed this dataclass already" and avoid rerunning this code, if that's indeed the case? That might stop anything similar from happening.
There was a problem hiding this comment.
Seems worth looking into! Codex generated this commit and it seemed like a more correct version of the previously existing code that attempted to make this logic idempotent, so I opened the PR
There was a problem hiding this comment.
This is documented in DataclassTransformer fwiw
There was a problem hiding this comment.
Ok, I see the other things have things like:
and (
"__match_args__" not in info.names or info.names["__match_args__"].plugin_generated
)
(which is basically what happens here)
Fixes python#17121 Generated by codex + hand simplification commit
Fixes python#17121 Generated by codex + hand simplification commit
Refresh all locked dependencies via `uv lock --upgrade`: 110 packages updated, 4 added, 6 removed. Notable moves: `mypy 1.19.1 -> 2.3.0`, `ruff 0.15.7 -> 0.16.1`, `numpy 2.4.3 -> 2.5.1`, `jax 0.9.2 -> 0.11.0`, `setuptools 82 -> 83`, `scipy 1.17.1 -> 1.18.0`, `cupy 14.0.1 -> 14.1.1`, `xarray 2026.2.0 -> 2026.7.0`. `dace` and `pybind11` are unchanged. The two QA tools are major bumps and turned `pre-commit run -a` red, so the second commit adapts the sources. ### ruff 0.16 New/expanded rules produced 31 errors on a previously clean tree: - 19x `Union[None, X]` reordered to put `None` last - 9x implicit string concatenation inside a collection literal, parenthesized explicitly - `FieldOffset` was listed twice in `gt4py.next.__all__` - `gtir_to_sdfg` was imported both at module level and under `TYPE_CHECKING` in `gtir_to_sdfg_primitives` - a trailing comma in `iterator/type_system/inference` made an assert message a 1-tuple instead of a string ruff 0.16 also formats code blocks inside markdown, which reformats six ADRs. CI runs `pre-commit --all-files`, so this is required rather than optional. ### mypy 2.3 18 errors: - 7 `type: ignore`s are now unused, including four in `instrumentation/metrics.py` that explicitly waited on python/mypy#20573, which 2.3 ships - 5 casts are redundant now that mypy narrows properly after the preceding `isinstance` (three of them already carried a comment saying the cast shouldn't be needed) - `Metric.mean` / `Metric.std` return `float` to match the numpy 2.5 stubs; at runtime these were and remain `np.float64`, and the only callers format them or wrap them in `float()` - `foast_passes/type_deduction`: the narrowing assert is split off the declared-type assignment - `next/utils.tree_map`: `isinstance(x, collection_type)` with a variable class object now narrows `Any` to `object`, so the length checks needed restructuring - `cartesian/utils/compiler`: `compiler_cxx` exists at runtime but is not declared on the `CCompiler` base class, so it gets a targeted ignore — the surrounding `except AttributeError` already handles the non-Unix case
Fixes #17121
Generated by codex + hand simplification commit