I’m using python with mysql-connector and am running my code through mypy and it’s complaining about types which I can’t seem to get around.
for instance. I have code like this
today = datetime.now().date()
mysql_cursor = mysql_connection.cursor()
cursor.execute( "select holiday_date from Holidays", {} )
rows = mysql_cursor.fetchall()
for row in rows:
holiday_date = row[ 0 ]
if holiday_date <= today:
print( holiday_date )
The Holidays table has a single column as.
holiday_date DATE NOT NULL
so I know that what will be returned will be python date objects but mypy is complaing…
error: Unsupported operand types for <= ("Decimal" and "date") [operator]
error: Unsupported operand types for <= ("bytes" and "date") [operator]
error: Unsupported operand types for <= ("float" and "date") [operator]
error: Unsupported operand types for <= ("int" and "date") [operator]
error: Unsupported operand types for <= ("set[str]" and "date") [operator]
error: Unsupported operand types for <= ("str" and "date") [operator]
error: Unsupported operand types for <= ("timedelta" and "date") [operator]
error: Unsupported operand types for <= ("time" and "date") [operator]
note: Left operand is of type "Any | Decimal | bytes | date | float | int | set[str] | str | timedelta | time | None"
I know that the column being returned is “typed” as it described above but I’m not sure how I coerce mypy into believing that the value is a date.
Any ideas?