Skip to content

propertize Callable attributes before freezing dataclasses #12383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 29, 2022

Conversation

uSpike
Copy link
Contributor

@uSpike uSpike commented Mar 19, 2022

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
Contributor Author

uSpike commented Mar 21, 2022

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

@uSpike
Copy link
Contributor Author

uSpike commented Mar 21, 2022

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
Contributor Author

uSpike commented Mar 21, 2022

Fixed linting error

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@jhance
Copy link
Collaborator

jhance commented Mar 23, 2022

Needs a rebase then I will merge.

@JelleZijlstra
Copy link
Member

I fixed the merge conflict

@github-actions
Copy link
Contributor

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

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

Callable types are not handled correctly in frozen dataclasses
3 participants