#30612: cached_property breaks type checking
-----------------------------------------+------------------------
Reporter: dms-cat | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
To reproduce:
1. Use a strict mypy configuration:
{{{
[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
}}}
1. Create a model method which returns an optional instance:
{{{
@property
def area(self) -> Optional[Area]:
}}}
1. Try to use this elsewhere as though it's not optional:
`instance.area.code`
1. Verify that `mypy` catches this issue:
{{{
error: Item "None" of "Optional[Area]" has no attribute "code"
}}}
1. Change the `@property` annotation to `@cached_property`.
What happens:
`mypy` stops complaining about the broken typing.
What should happen:
`mypy` should still complain like above.
--
Ticket URL: <https://code.djangoproject.com/ticket/30612>
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/050.2c4a27e2bde190fcce6c51b4f9e7d730%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.