#34809 closed Uncategorized (duplicate)

PyCharm typechecker complains

Reported by: Nils Lindemann Owned by: nobody
Component: Documentation Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

#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.

The related code example in the docs.

See also this Stack Overflow question.

Change History (3)

comment:1 by Nils Lindemann, 16 months ago

Summary: Pycharm typechecker complainsPyCharm typechecker complains

comment:2 by Nils Lindemann, 16 months ago

If someone could let me know where these docs are stored on GitHub, I can create a PR.

comment:3 by Mariusz Felisiak, 16 months ago

Component: UncategorizedDocumentation
Resolution: duplicate
Status: newclosed

Duplicate of #30345. Please leave a comment on the original ticket, if you like. I don't know why PyCharm is complaining but I don't see any issue here.

Note: See TracTickets for help on using tickets.
Back to Top