Title: Misleading "Not an instance or subtype" error when assigning to property of frozen, slotted dataclass · Issue #143969 · python/cpython · GitHub
Open Graph Title: Misleading "Not an instance or subtype" error when assigning to property of frozen, slotted dataclass · Issue #143969 · python/cpython
X Title: Misleading "Not an instance or subtype" error when assigning to property of frozen, slotted dataclass · Issue #143969 · python/cpython
Description: Bug report Bug description: When a dataclass is frozen, attempting to assign to a property (with a setter or without) fails as expected: from dataclasses import dataclass @dataclass(frozen=True) class Example: a: int @property def prop(s...
Open Graph Description: Bug report Bug description: When a dataclass is frozen, attempting to assign to a property (with a setter or without) fails as expected: from dataclasses import dataclass @dataclass(frozen=True) cl...
X Description: Bug report Bug description: When a dataclass is frozen, attempting to assign to a property (with a setter or without) fails as expected: from dataclasses import dataclass @dataclass(frozen=True) cl...
Opengraph URL: https://github.com/python/cpython/issues/143969
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Misleading \"Not an instance or subtype\" error when assigning to property of frozen, slotted dataclass","articleBody":"# Bug report\n\n### Bug description:\n\nWhen a dataclass is frozen, attempting to assign to a property (with a setter or without) fails as expected:\n\n```python\nfrom dataclasses import dataclass\n\n@dataclass(frozen=True)\nclass Example:\n\ta: int\n\n\t@property\n\tdef prop(self):\n\t\treturn None\n\nexample = Example(10)\nexample.prop = 0\n```\n```\n File \"test_dataclass.py\", line 12, in \u003cmodule\u003e\n example.prop = 0\n ^^^^^^^^^^^^\n File \"\u003cstring\u003e\", line 15, in __setattr__\ndataclasses.FrozenInstanceError: cannot assign to field 'prop'\n```\nAnd when the class is slotted, if the property has no setter, it also fails the way one would expect:\n```python\nfrom dataclasses import dataclass\n\n@dataclass(slots=True)\nclass Example:\n\ta: int\n\n\t@property\n\tdef prop(self):\n\t\treturn None\n\nexample = Example(10)\nexample.prop = 0\n```\n```\nTraceback (most recent call last):\n File \"test_dataclass.py\", line 12, in \u003cmodule\u003e\n example.prop = 0\n ^^^^^^^^^^^^\nAttributeError: property 'prop' of 'Example' object has no setter\n```\n(In this case, of course, adding a setter makes it work fine.)\n\nWhat's unexpected (and confusing) is when the class is both frozen *and* slotted:\n```python\nfrom dataclasses import dataclass\n\n@dataclass(frozen=True, slots=True)\nclass Example:\n\ta: int\n\n\t@property\n\tdef prop(self):\n\t\treturn None\n\nexample = Example(10)\nexample.prop = 0\n```\n```\nTraceback (most recent call last):\n File \"test_dataclass.py\", line 12, in \u003cmodule\u003e\n example.prop = 0\n ^^^^^^^^^^^^\n File \"\u003cstring\u003e\", line 16, in __setattr__\nTypeError: super(type, obj): obj (instance of Example) is not an instance or subtype of type (Example).\n```\nOne would, of course, expect an instance of `Example` to in fact be an instance of `Example`, but maybe this is somehow a collision between the initial vs. dataclass-ified class definitions?\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-143971\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/HalfWhitt","@type":"Person","name":"HalfWhitt"},"datePublished":"2026-01-17T15:51:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/143969/cpython/issues/143969"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:40dfe7b7-9152-5896-a3f8-71fe1bd2dd72 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9074:5C4F6:2DB2C9F:3C72B96:696DCC4F |
| html-safe-nonce | dcb3535a8d1572565583ad1559360027f6bbc3e19360800c5958a4d8ef485194 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDc0OjVDNEY2OjJEQjJDOUY6M0M3MkI5Njo2OTZEQ0M0RiIsInZpc2l0b3JfaWQiOiIzNjA3ODczNDM2MzcwNDU1NjMxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | adfa5aeab797d9bd5ff923878234c83bd06a598fd13a92e4258c0eceb873259d |
| hovercard-subject-tag | issue:3825444956 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/143969/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b1a519c649e6f48a6991723c8ceefaa201faad6053ac058a7ce750a5102761ea/python/cpython/issues/143969 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b1a519c649e6f48a6991723c8ceefaa201faad6053ac058a7ce750a5102761ea/python/cpython/issues/143969 |
| og:image:alt | Bug report Bug description: When a dataclass is frozen, attempting to assign to a property (with a setter or without) fails as expected: from dataclasses import dataclass @dataclass(frozen=True) cl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | HalfWhitt |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4922b452d03cd8dbce479d866a11bc25b59ef6ee2da23aa9b0ddefa6bd4d0064 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7e5ae23c70136152637ceee8d6faceb35596ec46 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width