Skip to content

Commit 15e4fe0

Browse files
committed
Remove questionable dataclass descriptor conformance assertions
1 parent 94514b1 commit 15e4fe0

4 files changed

Lines changed: 29 additions & 56 deletions

File tree

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
conformant = "Partial"
1+
conformant = "Pass"
22
notes = """
3-
Assumes descriptor behavior only when field is assigned in class body.
4-
Does not correctly evaluate type of descriptor access.
5-
"""
6-
output = """
7-
dataclasses_descriptors.py:61: error: Cannot access instance-only attribute "x" on class object [misc]
8-
dataclasses_descriptors.py:62: error: Cannot access instance-only attribute "y" on class object [misc]
9-
dataclasses_descriptors.py:66: error: Expression is of type "Desc2[int]", not "int" [assert-type]
10-
dataclasses_descriptors.py:67: error: Expression is of type "Desc2[str]", not "str" [assert-type]
11-
"""
12-
conformance_automated = "Fail"
13-
errors_diff = """
14-
Line 61: Unexpected errors ['dataclasses_descriptors.py:61: error: Cannot access instance-only attribute "x" on class object [misc]']
15-
Line 62: Unexpected errors ['dataclasses_descriptors.py:62: error: Cannot access instance-only attribute "y" on class object [misc]']
16-
Line 66: Unexpected errors ['dataclasses_descriptors.py:66: error: Expression is of type "Desc2[int]", not "int" [assert-type]']
17-
Line 67: Unexpected errors ['dataclasses_descriptors.py:67: error: Expression is of type "Desc2[str]", not "str" [assert-type]']
3+
Previously failed due to assumptions about non-data descriptor behavior in
4+
dataclasses that were removed from the conformance test because the behavior
5+
is currently under-specified.
186
"""
7+
conformance_automated = "Pass"
Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
1-
conformant = "Partial"
1+
conformant = "Pass"
22
notes = """
3-
Conformance suite is questionable; see https://github.com/python/typing/issues/2259
4-
"""
5-
conformance_automated = "Fail"
6-
errors_diff = """
7-
Line 61: Unexpected errors ['./dataclasses_descriptors.py:61:12: Any[error] is not equivalent to list[int]', "./dataclasses_descriptors.py:61:12: <class 'DC2'> has no attribute 'x' [undefined_attribute]"]
8-
Line 62: Unexpected errors ['./dataclasses_descriptors.py:62:12: Any[error] is not equivalent to list[str]', "./dataclasses_descriptors.py:62:12: <class 'DC2'> has no attribute 'y' [undefined_attribute]"]
9-
Line 63: Unexpected errors ['./dataclasses_descriptors.py:63:12: list[Any[generic_argument]] is not equivalent to list[str]']
10-
Line 66: Unexpected errors ['./dataclasses_descriptors.py:66:12: ./dataclasses_descriptors.py.Desc2[int] is not equivalent to int']
11-
Line 67: Unexpected errors ['./dataclasses_descriptors.py:67:12: ./dataclasses_descriptors.py.Desc2[str] is not equivalent to str']
12-
Line 68: Unexpected errors ['./dataclasses_descriptors.py:68:12: Any[generic_argument] is not equivalent to str']
13-
"""
14-
output = """
15-
./dataclasses_descriptors.py:61:12: Any[error] is not equivalent to list[int]
16-
./dataclasses_descriptors.py:61:12: <class 'DC2'> has no attribute 'x' [undefined_attribute]
17-
./dataclasses_descriptors.py:62:12: Any[error] is not equivalent to list[str]
18-
./dataclasses_descriptors.py:62:12: <class 'DC2'> has no attribute 'y' [undefined_attribute]
19-
./dataclasses_descriptors.py:63:12: list[Any[generic_argument]] is not equivalent to list[str]
20-
./dataclasses_descriptors.py:66:12: ./dataclasses_descriptors.py.Desc2[int] is not equivalent to int
21-
./dataclasses_descriptors.py:67:12: ./dataclasses_descriptors.py.Desc2[str] is not equivalent to str
22-
./dataclasses_descriptors.py:68:12: Any[generic_argument] is not equivalent to str
3+
Previously failed due to assumptions about non-data descriptor behavior in
4+
dataclasses that were removed from the conformance test because the behavior
5+
is currently under-specified.
236
"""
7+
conformance_automated = "Pass"
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
conformance_automated = "Fail"
2-
conformant = "Partial"
1+
conformance_automated = "Pass"
2+
conformant = "Pass"
33
notes = """
4-
Only infers a descriptor `__get__` method as being called when a descriptor attribute is accessed on an instance if the descriptor attribute is present in the class namespace.
5-
"""
6-
errors_diff = """
7-
Line 66: Unexpected errors ['dataclasses_descriptors.py:66:1: error[type-assertion-failure] Type `int | Desc2[int]` does not match asserted type `int`']
8-
Line 67: Unexpected errors ['dataclasses_descriptors.py:67:1: error[type-assertion-failure] Type `str | Desc2[str]` does not match asserted type `str`']
9-
"""
10-
output = """
11-
dataclasses_descriptors.py:66:1: error[type-assertion-failure] Type `int | Desc2[int]` does not match asserted type `int`
12-
dataclasses_descriptors.py:67:1: error[type-assertion-failure] Type `str | Desc2[str]` does not match asserted type `str`
4+
Previously failed due to assumptions about non-data descriptor behavior in
5+
dataclasses that were removed from the conformance test because the behavior
6+
is currently under-specified.
137
"""

conformance/tests/dataclasses_descriptors.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ class DC2:
5858
z: Desc2[str] = Desc2()
5959

6060

61-
assert_type(DC2.x, list[int])
62-
assert_type(DC2.y, list[str])
63-
assert_type(DC2.z, list[str])
64-
65-
dc2 = DC2(Desc2(), Desc2(), Desc2())
66-
assert_type(dc2.x, int)
67-
assert_type(dc2.y, str)
68-
assert_type(dc2.z, str)
61+
# Runtime behavior involving non-data descriptors in dataclasses is
62+
# currently under-specified and differs across type checkers and runtime
63+
# implementations.
64+
#
65+
# In particular:
66+
# - DC2.x and DC2.y raise AttributeError at runtime because no descriptor
67+
# instance is stored in the class dictionary for those fields.
68+
# - dc2.x and dc2.y evaluate to the stored Desc2 instances because
69+
# non-data descriptors are shadowed by instance attributes.
70+
# - The behavior for z is also subtle because dataclasses access the
71+
# descriptor during default extraction.
72+
#
73+
# These cases are therefore omitted from the conformance suite until the
74+
# expected behavior is specified more clearly.

0 commit comments

Comments
 (0)