#34809: Pycharm typechecker complains
-----------------------------------------+------------------------
               Reporter:  nilslindemann  |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  Uncategorized  |        Version:  4.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              |
-----------------------------------------+------------------------
 #30345 was closed, probably because it was not clear that the code will
 run, but the PyCharm type checker will complain. The solution posted
 there, namely, to write ...

 {{{
 return self.pub_date >= (timezone.now() -
 datetime.timedelta(days=1)).timestamp()
 }}}

 ... instead of ...

 {{{
 return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
 # PyCharm complains: "Expected type 'timedelta', got 'DateTimeField'
 instead"
 }}}

 ... will result in the correct type returned and PyCharm will not complain
 anymore.

 [https://django.readthedocs.io/en/stable/intro/tutorial02.html#playing-
 with-the-api The related code example in the docs].

 See also [https://stackoverflow.com/questions/61468142/pycharm-ide-
 warning-on-django-doc-expected-type-timedelta-got-datetimefield this Stack
 Overflow question].

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34809>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018a504bfda1-2d50f5b0-9b27-487e-a21f-c1813521b529-000000%40eu-central-1.amazonses.com.

Reply via email to