Commit f76d3f8
authored
[ty] Allow declared-only class-level attributes to be accessed on the class (astral-sh#19071)
## Summary
Allow declared-only class-level attributes to be accessed on the class:
```py
class C:
attr: int
C.attr # this is now allowed
```
closes astral-sh/ty#384
closes astral-sh/ty#553
## Ecosystem analysis
* We see many removed `unresolved-attribute` false-positives for code
that makes use of sqlalchemy, as expected (see changes for `prefect`)
* We see many removed `call-non-callable` false-positives for uses of
`pytest.skip` and similar, as expected
* Most new diagnostics seem to be related to cases like the following,
where we previously inferred `int` for `Derived().x`, but now we infer
`int | None`. I think this should be a
conflicting-declarations/bad-override error anyway? The new behavior may
even be preferred here?
```py
class Base:
x: int | None
class Derived(Base):
def __init__(self):
self.x: int = 1
```1 parent 5f426b9 commit f76d3f8
File tree
6 files changed
+37
-68
lines changed- crates/ty_python_semantic
- resources/mdtest
- call
- type_qualifiers
- src
6 files changed
+37
-68
lines changedLines changed: 17 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 90 | + | |
94 | 91 | | |
95 | | - | |
96 | | - | |
97 | 92 | | |
98 | 93 | | |
99 | 94 | | |
| |||
102 | 97 | | |
103 | 98 | | |
104 | 99 | | |
105 | | - | |
106 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
107 | 105 | | |
108 | 106 | | |
109 | 107 | | |
| |||
113 | 111 | | |
114 | 112 | | |
115 | 113 | | |
116 | | - | |
117 | | - | |
118 | | - | |
| 114 | + | |
119 | 115 | | |
120 | | - | |
121 | 116 | | |
122 | 117 | | |
123 | 118 | | |
| |||
1235 | 1230 | | |
1236 | 1231 | | |
1237 | 1232 | | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
1238 | 1243 | | |
1239 | 1244 | | |
1240 | 1245 | | |
| |||
1299 | 1304 | | |
1300 | 1305 | | |
1301 | 1306 | | |
1302 | | - | |
1303 | 1307 | | |
1304 | 1308 | | |
1305 | | - | |
1306 | 1309 | | |
1307 | 1310 | | |
1308 | 1311 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
124 | | - | |
| 123 | + | |
125 | 124 | | |
126 | 125 | | |
127 | 126 | | |
128 | 127 | | |
129 | 128 | | |
130 | 129 | | |
131 | 130 | | |
132 | | - | |
133 | 131 | | |
134 | 132 | | |
135 | | - | |
136 | 133 | | |
137 | 134 | | |
138 | 135 | | |
| |||
Lines changed: 0 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
810 | 810 | | |
811 | 811 | | |
812 | 812 | | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | | - | |
817 | | - | |
818 | | - | |
819 | | - | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | 813 | | |
829 | 814 | | |
830 | 815 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
537 | 543 | | |
538 | 544 | | |
539 | 545 | | |
| |||
1586 | 1592 | | |
1587 | 1593 | | |
1588 | 1594 | | |
1589 | | - | |
1590 | | - | |
1591 | | - | |
1592 | | - | |
1593 | | - | |
| 1595 | + | |
1594 | 1596 | | |
1595 | 1597 | | |
1596 | 1598 | | |
| |||
1599 | 1601 | | |
1600 | 1602 | | |
1601 | 1603 | | |
1602 | | - | |
| 1604 | + | |
1603 | 1605 | | |
1604 | 1606 | | |
1605 | 1607 | | |
| |||
1832 | 1834 | | |
1833 | 1835 | | |
1834 | 1836 | | |
1835 | | - | |
| 1837 | + | |
| 1838 | + | |
1836 | 1839 | | |
1837 | 1840 | | |
1838 | 1841 | | |
| |||
Lines changed: 0 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | 67 | | |
86 | 68 | | |
87 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
238 | | - | |
239 | | - | |
| 238 | + | |
| 239 | + | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
| 242 | + | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
251 | 250 | | |
252 | 251 | | |
253 | 252 | | |
254 | 253 | | |
255 | 254 | | |
256 | | - | |
| 255 | + | |
257 | 256 | | |
258 | 257 | | |
259 | 258 | | |
260 | | - | |
| 259 | + | |
261 | 260 | | |
262 | 261 | | |
263 | 262 | | |
| |||
0 commit comments