Skip to content

Fix type overrides for string-annotated dataclasses - #809

Open
repzakske wants to merge 1 commit into
python-attrs:mainfrom
repzakske:fix/dataclass-string-type-overrides
Open

repzakske wants to merge 1 commit into
python-attrs:mainfrom
repzakske:fix/dataclass-string-type-overrides

Conversation

@repzakske

Copy link
Copy Markdown

With stringified dataclass annotations (including from __future__ import annotations), converter type_overrides are looked up using strings such as "int" instead of the resolved types. For example, Converter(type_overrides={int: override(omit_if_default=True)}) exports a default-valued retries: int = 3 field instead of omitting it. A rename override is also ignored when loading data, so the configured input key fails with a missing-field error. Eager annotations and attrs classes already work.

Use the existing adapted_fields() helper before selecting type overrides in both generated dict-hook entry points. It resolves dataclass annotations and retains the existing handling of attrs classes and generic origins. Add regression coverage for default omission, non-default values, renaming in both directions, both validation modes, and eager-annotation controls. Include a history entry.

Validation on Windows:

  • On the unchanged baseline, the three string-annotation cases fail and the three eager-annotation controls pass on Python 3.10 and 3.14.
  • All six cases pass with the fix.
  • Full suite on Python 3.14.8: 1,090 passed, 2 skipped, 15 xfailed, including the mypy/Pyrefly typing tests.
  • Full suite on Python 3.10.16: 1,018 passed, 9 skipped, 15 xfailed. Pytest reports two config warnings because the typing-test plugin is enabled only on Python 3.14 by the project's dependency group.
  • Repository-configured Ruff lint and formatting pass; wheel and sdist builds pass.

Other operating systems and the remaining Python versions have not been tested locally. Upstream CI has not run.

Signed-off-by: Casper Verbuyst <casperverbuyst@gmail.com>
@codspeed

codspeed Bot commented Oct 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 note

ℹ️ 64 benchmarks have no flamegraph

The flamegraph wasn't generated: the symbols of the profiling trace could not be resolved, because no information about the language frames was collected.

See affected benchmarks

✅ 64 untouched benchmarks


Comparing repzakske:fix/dataclass-string-type-overrides (646b397) with main (2c6cf5b)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (57333a2) during the generation of this report, so 2c6cf5b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

This branch has not been deployed

No deployments
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.

1 participant