Skip to content

Fix slots issue with deferred base - #20573

Merged
hauntsaninja merged 2 commits into
python:masterfrom
hauntsaninja:slotfix
Jan 14, 2026
Merged

Fix slots issue with deferred base#20573
hauntsaninja merged 2 commits into
python:masterfrom
hauntsaninja:slotfix

Conversation

@hauntsaninja

@hauntsaninja hauntsaninja commented Jan 13, 2026

Copy link
Copy Markdown
Collaborator

Fixes #17121

Generated by codex + hand simplification commit

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Comment on lines +461 to +462
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:

@A5rocks A5rocks Jan 13, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think the deferral led to this being called multiple times

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is documented in DataclassTransformer fwiw

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also #12762

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@hauntsaninja
hauntsaninja merged commit 458fb36 into python:master Jan 14, 2026
23 checks passed
@hauntsaninja
hauntsaninja deleted the slotfix branch January 14, 2026 02:59
michaelm-openai pushed a commit to michaelm-openai/mypy that referenced this pull request Jan 16, 2026
Fixes python#17121

Generated by codex + hand simplification commit
michaelm-openai pushed a commit to michaelm-openai/mypy that referenced this pull request Jan 16, 2026
Fixes python#17121

Generated by codex + hand simplification commit
havogt added a commit to GridTools/gt4py that referenced this pull request Aug 10, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spurious error for dataclass(slots=True)

3 participants