Skip to content

Commit 3f4c859

Browse files
Fix descriptor access for dataclass fields
1 parent 7489125 commit 3f4c859

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

mypy/checkmember.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,12 +936,16 @@ def analyze_var(
936936
):
937937
# Unwrap nonmember similar to class-level access
938938
result = p_result.args[0]
939+
dataclass_metadata = var.info.metadata.get("dataclass", {})
940+
is_dataclass_field = any(
941+
attribute.get("name") == name for attribute in dataclass_metadata.get("attributes", [])
942+
)
939943
# A read-only property has already applied descriptor access to its getter
940-
# result. Settable properties may represent dataclass-transform descriptors,
941-
# which still require the normal descriptor access on instance reads.
944+
# result. Dataclass fields are represented as synthetic properties, but
945+
# their descriptor access still needs to happen on instance reads.
942946
if (
943947
result
944-
and not (var.is_property and not var.is_settable_property)
948+
and not (var.is_property and not var.is_settable_property and not is_dataclass_field)
945949
and not (implicit or var.info.is_protocol and is_instance_var(var))
946950
):
947951
result = analyze_descriptor_access(result, mx)

0 commit comments

Comments
 (0)