#30612: cached_property breaks type checking
---------------------------+--------------------------------------
Reporter: dms-cat | Owner: nobody
Type: Bug | Status: closed
Component: Utilities | Version: master
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------+--------------------------------------
Comment (by dms-cat):
Replying to [comment:1 felixxm]:
> Please provide a minimal sample project to reproduce this issue,
currently it is hard for me to decide where is an issue (if any).
To reproduce (not showing stdout/stderr):
{{{
$ cd "$(mktemp --directory)"
$ python -m venv virtualenv
$ . virtualenv/bin/activate
$ pip install Django==2.2.2 mypy==0.701
$ django-admin startproject mysite
$ cat > setup.cfg <<EOF
> [mypy]
> check_untyped_defs = true
> disallow_untyped_defs = true
> ignore_missing_imports = true
> no_implicit_optional = true
> warn_redundant_casts = true
> warn_return_any = true
> warn_unused_ignores = true
> EOF
cat > mysite/mysite/models.py <<EOF
from typing import Optional
from django.db import models
from django.utils import cached_property
class Area(models.Model):
pass
class Site(models.Model):
area = models.ForeignKey(Area, on_delete=models.CASCADE)
@cached_property
def the_area(self) -> Optional[Area]:
area: Area = self.area
return area
area = Area.objects.create()
site = Site(area)
print(site.the_area.code)
EOF
$ mypy mysite/mysite/models.py
}}}
The last command reports nothing. If you change `@cached_property` to
`@property` it correctly reports 'mysite/mysite/models.py:22: error: Item
"None" of "Optional[Area]" has no attribute "code"'
> Remember about minimal `mypy` configuration, most of provided custom
configuration is probably unnecessary.
This isn't provided configuration, we arrived at this configuration in the
project as the level of validation we're comfortable with.
--
Ticket URL: <https://code.djangoproject.com/ticket/30612#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.0879c6159baad21217f381f44ebf6e35%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.