Skip to content

propertize Callable attributes before freezing dataclasses - #12383

Merged
jhance merged 4 commits into
python:masterfrom
uSpike:12312-dataclass-frozen-callable
Mar 29, 2022
Merged

propertize Callable attributes before freezing dataclasses#12383
jhance merged 4 commits into
python:masterfrom
uSpike:12312-dataclass-frozen-callable

Conversation

@uSpike

@uSpikeuSpike commented Mar 19, 2022

Copy link
Copy Markdown
Contributor

Description

Fixes: #12312

Related: #10292

Callable attributes of a frozen=True dataclass were not being handled correctly: Callable attributes were being propertized if the dataclass was not frozen.

This change will always propertize Callable attributes before optionally freezing attributes in the dataclass plugin.

Test Plan

Added a test for Callable types in a frozen dataclass to test-data/unit/check-dataclasses.test

@github-actions

This comment has been minimized.

@uSpike

Copy link
Copy Markdown
ContributorAuthor

I need to rethink this because this does not raise an error when a frozen dataclass Callable method is mutated.

@uSpike

Copy link
Copy Markdown
ContributorAuthor

OK I think I've fixed it so that propertized callables are not writable when frozen. This PR should be ready for review

@uSpike

Copy link
Copy Markdown
ContributorAuthor

Fixed linting error

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@jhance

Copy link
Copy Markdown
Collaborator

Needs a rebase then I will merge.

@JelleZijlstra

Copy link
Copy Markdown
Member

I fixed the merge conflict

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@jhance
jhance merged commit a33d235 into python:masterMar 29, 2022
@uSpike
uSpike deleted the 12312-dataclass-frozen-callable branch March 29, 2022 18:00
Sign up for freeto 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.

Callable types are not handled correctly in frozen dataclasses

3 participants

@uSpike@jhance@JelleZijlstra