Created
November 17, 2024 19:57
-
-
Save foxmask/a26f0c171e4a4ba1737ff7d2eb0e7611 to your computer and use it in GitHub Desktop.
mypy Unsupported operand types for + ("str" and "timedelta") [operator]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maillepaille.py:10: error: Incompatible types in assignment (expression has type "datetime", variable has type "str") [assignment] | |
maillepaille.py:15: error: Incompatible types in assignment (expression has type "date", variable has type "str") [assignment] | |
maillepaille.py:17: error: Incompatible types in assignment (expression has type "datetime", variable has type "str") [assignment] | |
maillepaille.py:19: error: Unsupported operand types for + ("str" and "timedelta") [operator] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date, datetime, timedelta, timezone | |
import pytz | |
yesterday = "" | |
now = datetime.now(tz=pytz.timezone("Europe/London")) | |
today = date.today() | |
if yesterday: | |
yesterday = datetime.strptime(yesterday, "%Y-%m-%d").replace(tzinfo=timezone.utc) | |
start_of_day = yesterday | |
else: | |
yesterday = today - timedelta(days=1, seconds=-1) | |
start_of_day = datetime(now.year, now.month, now.day) | |
end_of_day = start_of_day + timedelta(days=1, seconds=-1) |
Nomme la variable différement quand c'est une chaîne et une date alors, ça aidera mypy à suivre.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yesterday est un query parameter qui vient de l'url genre http://localhost:8000?yesterday=2020-01-01
dans ma fonction qui la recupere c'est bien une string que je transforme en datetime comme on voit ligne 10
je viens de tester et declarer yesterday: date | None = None, parmi les parms de la fonction fonctionne (j'aurai appris un truc different de django sur ce coup là)