@@ -39,7 +39,36 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/type_qualifiers/final.md
393924 | c.x = 2 # error: [invalid-assignment]
404025 | from typing import Final
414126 |
42- 27 | UNINITIALIZED: Final[int] # error: [final-without-value]
42+ 27 | class C:
43+ 28 | x: Final[int] # error: [final-without-value]
44+ 29 |
45+ 30 | def f(self):
46+ 31 | self.x = 2 # error: [invalid-assignment]
47+ 32 | from typing import Final
48+ 33 |
49+ 34 | class C:
50+ 35 | x: Final[int] = 1
51+ 36 |
52+ 37 | def __init__(self):
53+ 38 | self.x = 2 # error: [invalid-assignment]
54+ 39 | from typing import Final
55+ 40 |
56+ 41 | class Base:
57+ 42 | x: Final[int] = 1
58+ 43 |
59+ 44 | class Child(Base):
60+ 45 | def f(self):
61+ 46 | self.x = 2 # error: [invalid-assignment]
62+ 47 | from typing import Final
63+ 48 |
64+ 49 | class C:
65+ 50 | x: int
66+ 51 |
67+ 52 | def f(self):
68+ 53 | self.x: Final[int] = 1 # error: [invalid-assignment]
69+ 54 | from typing import Final
70+ 55 |
71+ 56 | UNINITIALIZED: Final[int] # error: [final-without-value]
4372` ` `
4473
4574# Diagnostics
@@ -79,8 +108,12 @@ info: rule `invalid-assignment` is enabled by default
79108
80109` ` `
81110error[invalid-assignment]: Cannot assign to final attribute ` x ` on type ` Self @f `
82- --> src/mdtest_snippet.py:17:9
111+ --> src/mdtest_snippet.py:14:8
83112 |
113+ 13 | class C:
114+ 14 | x: Final[int] = 1
115+ | ---------- Attribute declared as ` Final ` here
116+ 15 |
8411716 | def f(self):
8511817 | self.x = 2 # error: [invalid-assignment]
86119 | ^^^^^^ ` Final ` attributes can only be assigned in the class body or ` __init__ `
@@ -92,8 +125,12 @@ info: rule `invalid-assignment` is enabled by default
92125
93126` ` `
94127error[invalid-assignment]: Cannot assign to final attribute ` x ` on type ` C `
95- --> src/mdtest_snippet.py:24:5
128+ --> src/mdtest_snippet.py:21:8
96129 |
130+ 20 | class C:
131+ 21 | x: Final[int] = 1
132+ | ---------- Attribute declared as ` Final ` here
133+ 22 |
9713423 | def __init__(c: C):
9813524 | c.x = 2 # error: [invalid-assignment]
99136 | ^^^ ` Final ` attributes can only be assigned in the class body or ` __init__ `
@@ -103,13 +140,92 @@ info: rule `invalid-assignment` is enabled by default
103140
104141` ` `
105142
143+ ` ` `
144+ error[final-without-value]: ` Final ` symbol ` x ` is not assigned a value
145+ --> src/mdtest_snippet.py:28:5
146+ |
147+ 27 | class C:
148+ 28 | x: Final[int] # error: [final-without-value]
149+ | ^^^^^^^^^^^^^
150+ 29 |
151+ 30 | def f(self):
152+ |
153+ info: rule ` final - without - value ` is enabled by default
154+
155+ ` ` `
156+
157+ ` ` `
158+ error[invalid-assignment]: Cannot assign to final attribute ` x ` on type ` Self @f `
159+ --> src/mdtest_snippet.py:28:8
160+ |
161+ 27 | class C:
162+ 28 | x: Final[int] # error: [final-without-value]
163+ | ---------- Attribute declared as ` Final ` here
164+ 29 |
165+ 30 | def f(self):
166+ 31 | self.x = 2 # error: [invalid-assignment]
167+ | ^^^^^^ ` Final ` attributes can only be assigned in the class body or ` __init__ `
168+ 32 | from typing import Final
169+ |
170+ info: rule ` invalid - assignment ` is enabled by default
171+
172+ ` ` `
173+
174+ ` ` `
175+ error[invalid-assignment]: Invalid assignment to final attribute
176+ --> src/mdtest_snippet.py:35:8
177+ |
178+ 34 | class C:
179+ 35 | x: Final[int] = 1
180+ | ---------- Attribute declared as ` Final ` here
181+ 36 |
182+ 37 | def __init__(self):
183+ 38 | self.x = 2 # error: [invalid-assignment]
184+ | ^^^^^^ ` x ` already has a value in the class body
185+ 39 | from typing import Final
186+ |
187+ info: rule ` invalid - assignment ` is enabled by default
188+
189+ ` ` `
190+
191+ ` ` `
192+ error[invalid-assignment]: Cannot assign to final attribute ` x ` on type ` Self @f `
193+ --> src/mdtest_snippet.py:42:8
194+ |
195+ 41 | class Base:
196+ 42 | x: Final[int] = 1
197+ | ---------- Attribute declared as ` Final ` here
198+ 43 |
199+ 44 | class Child(Base):
200+ 45 | def f(self):
201+ 46 | self.x = 2 # error: [invalid-assignment]
202+ | ^^^^^^ ` Final ` attributes can only be assigned in the class body or ` __init__ `
203+ 47 | from typing import Final
204+ |
205+ info: rule ` invalid - assignment ` is enabled by default
206+
207+ ` ` `
208+
209+ ` ` `
210+ error[invalid-assignment]: Cannot assign to final attribute ` x ` on type ` Self @f `
211+ --> src/mdtest_snippet.py:53:9
212+ |
213+ 52 | def f(self):
214+ 53 | self.x: Final[int] = 1 # error: [invalid-assignment]
215+ | ^^^^^^ ` Final ` attributes can only be assigned in the class body or ` __init__ `
216+ 54 | from typing import Final
217+ |
218+ info: rule ` invalid - assignment ` is enabled by default
219+
220+ ` ` `
221+
106222` ` `
107223error[final-without-value]: ` Final ` symbol ` UNINITIALIZED ` is not assigned a value
108- --> src/mdtest_snippet.py:27 :1
224+ --> src/mdtest_snippet.py:56 :1
109225 |
110- 25 | from typing import Final
111- 26 |
112- 27 | UNINITIALIZED: Final[int] # error: [final-without-value]
226+ 54 | from typing import Final
227+ 55 |
228+ 56 | UNINITIALIZED: Final[int] # error: [final-without-value]
113229 | ^^^^^^^^^^^^^^^^^^^^^^^^^
114230 |
115231info: rule ` final - without - value ` is enabled by default
0 commit comments