Commit a3aac71
authored
Hi!
We, in `django-stubs`, have a lot of usages of `@cached_property`
decorator that is a part of `django`:
https://docs.djangoproject.com/en/5.2/ref/utils/#django.utils.functional.cached_property
All usages of it we have to add to `subtest/allowlist.txt`, which is not
great. In typing we reuse `@functools.cached_property` to have all the
benefits of its inference:
https://github.com/typeddjango/django-stubs/blob/ee8e8b11c37866969ff0406be20591a067dfa983/django-stubs/utils/functional.pyi#L3-L4
But, `stubtest` is not happy with this move: because in runtime objects
have `django.utils.functional.cached_property` type and we see the
following error:
```
error: django.http.response.HttpResponse.text is inconsistent, cannot reconcile @Property on stub with runtime object
Stub: in file /home/runner/work/django-stubs/django-stubs/django-stubs/http/response.pyi:106
def (self: django.http.response.HttpResponse) -> builtins.str
Runtime:
<django.utils.functional.cached_property object at 0x7f7ce7704920>
```
So, we add all `@django.utils.functional.cached_property` usages to our
`allowlist.txt`. There are LOTS of entries there:
https://github.com/typeddjango/django-stubs/blob/ee8e8b11c37866969ff0406be20591a067dfa983/scripts/stubtest/allowlist.txt#L158-L425
Moreover, we have to always tell about this problem to new contributors
on review :(
That's why I propose to special case this as we do with other
`property`-likes.
I've tested locally and it works perfectly. I don't want to complicate
the CI with `django` installation and special tests. So, I added `#
pragma: no cover` to indicate that it is not tested.
1 parent 501a07b commit a3aac71
1 file changed
+16
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1256 | 1256 | | |
1257 | 1257 | | |
1258 | 1258 | | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
1259 | 1272 | | |
1260 | 1273 | | |
1261 | 1274 | | |
| |||
1264 | 1277 | | |
1265 | 1278 | | |
1266 | 1279 | | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
1267 | 1283 | | |
1268 | 1284 | | |
1269 | 1285 | | |
| |||
0 commit comments