[ty] Support frozen dataclasses by thejchap · Pull Request #17974 · astral-sh/ruff (original) (raw)

carljm

AlexWaygood

carljm

@thejchap @carljm

Markdown formatting

Co-authored-by: Alex Waygood Alex.Waygood@Gmail.com

@thejchap @carljm

@carljm

sharkdp

sharkdp added a commit that referenced this pull request

Jul 8, 2025

@thejchap @sharkdp

#18347)

Summary

Related:

Previously, when validating an attribute assignment, a __setattr__ call check was only done if the attribute wasn't found as either a class member or instance member

This PR changes the __setattr__ call check to be attempted first, prior to the "normal mechanism", as a defined __setattr__ should take precedence over setting an attribute on the instance dictionary directly.

if the return type of __setattr__ is Never, an invalid-assignment diagnostic is emitted

Once this is merged, a subsequent PR will synthesize a __setattr__ method with a Never return type for frozen dataclasses.

Test Plan

Existing tests + mypy_primer


Co-authored-by: David Peter mail@david-peter.de

sharkdp added a commit that referenced this pull request

Jul 18, 2025

@thejchap @sharkdp

KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request

May 1, 2026

@thejchap @sharkdp

…t (#18347)

Summary

Related:

Previously, when validating an attribute assignment, a __setattr__ call check was only done if the attribute wasn't found as either a class member or instance member

This PR changes the __setattr__ call check to be attempted first, prior to the "normal mechanism", as a defined __setattr__ should take precedence over setting an attribute on the instance dictionary directly.

if the return type of __setattr__ is Never, an invalid-assignment diagnostic is emitted

Once this is merged, a subsequent PR will synthesize a __setattr__ method with a Never return type for frozen dataclasses.

Test Plan

Existing tests + mypy_primer


Co-authored-by: David Peter mail@david-peter.de

KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request

May 1, 2026

@thejchap @sharkdp

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})