Skip to content

Conversation

@srittau
Copy link
Collaborator

@srittau srittau commented Apr 29, 2024

No description provided.

@srittau
Copy link
Collaborator Author

srittau commented Apr 29, 2024

This is a trial to judge the impact of such a change that could prevent runtime errors due to mixing timezone-aware and unaware datetimes.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@srittau
Copy link
Collaborator Author

srittau commented Apr 29, 2024

While I think there's some promise in this approach, I struggle with Any annotated datetimes. The __sub__ overloads (for example), derive a return type of Any, probably because mypy is merging the timedelta and NoReturn annotations of multiple annotations. Does anyone have an idea how to work around this?

@bluetech
Copy link
Contributor

I don't have much to add except to say that having this will be truly great, my code is littered with "aware"/"not aware" comments which really should be in the type, so I hope you can get it to work. (I haven't been bothered with it enough to use something like DataType yet).

I am curious about two things:

  • Why default TzInfoT to Any instead of tzinfo | None?
  • Why are the overloads needed? I guess typecheckers don't know the type of default values so they don't see that fromtimestamp(123) is the same as fromtimestamp(123, tz=None) and so can't infer TzInfoT=None?

@srittau
Copy link
Collaborator Author

srittau commented May 19, 2024

@bluetech

  • Why default TzInfoT to Any instead of tzinfo | None?

It tried both, but both didn't work. tzinfo | None is also my preferred default, but I hoped that Any would have less problems when it didn't.

  • Why are the overloads needed? I guess typecheckers don't know the type of default values so they don't see that fromtimestamp(123) is the same as fromtimestamp(123, tz=None) and so can't infer TzInfoT=None?

Exactly.

@github-actions

This comment has been minimized.

@srittau srittau linked an issue Nov 10, 2025 that may be closed by this pull request
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pandera (https://github.com/pandera-dev/pandera)
- pandera/engines/pandas_engine.py:972: error: Argument 1 to "Timestamp" has incompatible type "Any | Hashable"; expected "integer[Any] | float | str | date | datetime | datetime64[date | int | None]"  [arg-type]
+ pandera/engines/pandas_engine.py:972: error: Argument 1 to "Timestamp" has incompatible type "Any | Hashable"; expected "integer[Any] | float | str | date | datetime[Any] | datetime64[date | int | None]"  [arg-type]
- pandera/engines/pandas_engine.py:973: error: Argument 1 to "Timestamp" has incompatible type "Any | Hashable"; expected "integer[Any] | float | str | date | datetime | datetime64[date | int | None]"  [arg-type]
+ pandera/engines/pandas_engine.py:973: error: Argument 1 to "Timestamp" has incompatible type "Any | Hashable"; expected "integer[Any] | float | str | date | datetime[Any] | datetime64[date | int | None]"  [arg-type]
- pandera/engines/pandas_engine.py:974: error: Argument 1 to "Timestamp" has incompatible type "Any | Hashable"; expected "integer[Any] | float | str | date | datetime | datetime64[date | int | None]"  [arg-type]
+ pandera/engines/pandas_engine.py:974: error: Argument 1 to "Timestamp" has incompatible type "Any | Hashable"; expected "integer[Any] | float | str | date | datetime[Any] | datetime64[date | int | None]"  [arg-type]
- pandera/strategies/pandas_strategies.py:68: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime | timedelta | <15 more items> | None = ..., *, inplace: Literal[True], axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> None
+ pandera/strategies/pandas_strategies.py:68: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime[Any] | timedelta | <15 more items> | None = ..., *, inplace: Literal[True], axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> None
- pandera/strategies/pandas_strategies.py:68: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime | timedelta | <15 more items> | None = ..., *, inplace: Literal[False] = ..., axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> Series[Any]
+ pandera/strategies/pandas_strategies.py:68: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime[Any] | timedelta | <15 more items> | None = ..., *, inplace: Literal[False] = ..., axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> Series[Any]
- pandera/strategies/pandas_strategies.py:70: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime | timedelta | <15 more items> | None = ..., *, inplace: Literal[True], axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> None
+ pandera/strategies/pandas_strategies.py:70: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime[Any] | timedelta | <15 more items> | None = ..., *, inplace: Literal[True], axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> None
- pandera/strategies/pandas_strategies.py:70: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime | timedelta | <15 more items> | None = ..., *, inplace: Literal[False] = ..., axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> Series[Any]
+ pandera/strategies/pandas_strategies.py:70: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime[Any] | timedelta | <15 more items> | None = ..., *, inplace: Literal[False] = ..., axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> Series[Any]
- pandera/strategies/pandas_strategies.py:71: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime | timedelta | <15 more items> | None = ..., *, inplace: Literal[True], axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> None
+ pandera/strategies/pandas_strategies.py:71: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime[Any] | timedelta | <15 more items> | None = ..., *, inplace: Literal[True], axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> None
- pandera/strategies/pandas_strategies.py:71: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime | timedelta | <15 more items> | None = ..., *, inplace: Literal[False] = ..., axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> Series[Any]
+ pandera/strategies/pandas_strategies.py:71: note:     def mask(self, cond: Series[Any] | Series[bool] | ndarray[tuple[Any, ...], dtype[Any]] | Callable[[Series[Any]], Series[bool]] | Callable[[Any], bool], other: str | bytes | date | datetime[Any] | timedelta | <15 more items> | None = ..., *, inplace: Literal[False] = ..., axis: Literal['index', 0] | None = ..., level: Hashable | None = ...) -> Series[Any]

spark (https://github.com/apache/spark)
- python/pyspark/sql/pandas/types.py:755: error: Argument 1 to "apply" of "Series" has incompatible type "Callable[[Any], Any | NaTType]"; expected "Callable[..., str | bytes | date | datetime | timedelta | <16 more items> | None]"  [arg-type]
+ python/pyspark/sql/pandas/types.py:755: error: Argument 1 to "apply" of "Series" has incompatible type "Callable[[Any], Any | NaTType]"; expected "Callable[..., str | bytes | date | datetime[Any] | timedelta | <16 more items> | None]"  [arg-type]
- python/pyspark/sql/pandas/types.py:755: error: Incompatible return value type (got "Any | NaTType", expected "str | bytes | date | datetime | timedelta | <16 more items> | None")  [return-value]
+ python/pyspark/sql/pandas/types.py:755: error: Incompatible return value type (got "Any | NaTType", expected "str | bytes | date | datetime[Any] | timedelta | <16 more items> | None")  [return-value]
- python/pyspark/pandas/indexing.py:177: error: Incompatible return value type (got "ExtensionArray | ndarray[tuple[Any, ...], dtype[Any]] | Any", expected "Series[Any] | DataFrame[Any] | int | float | bool | str | bytes | Decimal | date | datetime | None")  [return-value]
+ python/pyspark/pandas/indexing.py:177: error: Incompatible return value type (got "ExtensionArray | ndarray[tuple[Any, ...], dtype[Any]] | Any", expected "Series[Any] | DataFrame[Any] | int | float | bool | str | bytes | Decimal | date | datetime[Any] | None")  [return-value]
- python/pyspark/pandas/generic.py:2681: error: Incompatible return value type (got "Series[Any]", expected "int | float | bool | str | bytes | Decimal | date | datetime | None | tuple[int | float | bool | str | bytes | Decimal | date | datetime | None, ...] | None")  [return-value]
+ python/pyspark/pandas/generic.py:2681: error: Incompatible return value type (got "Series[Any]", expected "int | float | bool | str | bytes | Decimal | date | datetime[Any] | None | tuple[int | float | bool | str | bytes | Decimal | date | datetime[Any] | None, ...] | None")  [return-value]
- python/pyspark/pandas/generic.py:3088: error: Incompatible return value type (got "Series[Any] | pandas.core.frame.DataFrame | str | bytes | date | <9 more items>", expected "int | float | bool | str | bytes | Decimal | date | datetime | None | pyspark.pandas.frame.DataFrame[Any] | Series[Any]")  [return-value]
+ python/pyspark/pandas/generic.py:3088: error: Incompatible return value type (got "Series[Any] | pandas.core.frame.DataFrame | str | bytes | date | <9 more items>", expected "int | float | bool | str | bytes | Decimal | date | datetime[Any] | None | pyspark.pandas.frame.DataFrame[Any] | Series[Any]")  [return-value]
- python/pyspark/pandas/namespace.py:1920: note:     def date_range(start: str | date | datetime | datetime64[date | int | None] | Timestamp, end: str | date | datetime | datetime64[date | int | None] | Timestamp, freq: str | timedelta | Timedelta | BaseOffset | None = ..., tz: str | tzinfo | int | None = ..., normalize: bool = ..., name: Hashable | None = ..., inclusive: Literal['both', 'neither'] | Literal['left', 'right'] = ..., unit: Literal['s', 'ms', 'us', 'ns'] | None = ...) -> DatetimeIndex
+ python/pyspark/pandas/namespace.py:1920: note:     def date_range(start: str | date | datetime[Any] | datetime64[date | int | None] | Timestamp, end: str | date | datetime[Any] | datetime64[date | int | None] | Timestamp, freq: str | timedelta | Timedelta | BaseOffset | None = ..., tz: str | tzinfo | int | None = ..., normalize: bool = ..., name: Hashable | None = ..., inclusive: Literal['both', 'neither'] | Literal['left', 'right'] = ..., unit: Literal['s', 'ms', 'us', 'ns'] | None = ...) -> DatetimeIndex
- python/pyspark/pandas/namespace.py:1920: note:     def date_range(start: str | date | datetime | datetime64[date | int | None] | Timestamp, end: str | date | datetime | datetime64[date | int | None] | Timestamp, periods: int, tz: str | tzinfo | int | None = ..., normalize: bool = ..., name: Hashable | None = ..., inclusive: Literal['both', 'neither'] | Literal['left', 'right'] = ..., unit: Literal['s', 'ms', 'us', 'ns'] | None = ...) -> DatetimeIndex
+ python/pyspark/pandas/namespace.py:1920: note:     def date_range(start: str | date | datetime[Any] | datetime64[date | int | None] | Timestamp, end: str | date | datetime[Any] | datetime64[date | int | None] | Timestamp, periods: int, tz: str | tzinfo | int | None = ..., normalize: bool = ..., name: Hashable | None = ..., inclusive: Literal['both', 'neither'] | Literal['left', 'right'] = ..., unit: Literal['s', 'ms', 'us', 'ns'] | None = ...) -> DatetimeIndex
- python/pyspark/pandas/namespace.py:1920: note:     def date_range(start: str | date | datetime | datetime64[date | int | None] | Timestamp, *, periods: int, freq: str | timedelta | Timedelta | BaseOffset | None = ..., tz: str | tzinfo | int | None = ..., normalize: bool = ..., name: Hashable | None = ..., inclusive: Literal['both', 'neither'] | Literal['left', 'right'] = ..., unit: Literal['s', 'ms', 'us', 'ns'] | None = ...) -> DatetimeIndex
+ python/pyspark/pandas/namespace.py:1920: note:     def date_range(start: str | date | datetime[Any] | datetime64[date | int | None] | Timestamp, *, periods: int, freq: str | timedelta | Timedelta | BaseOffset | None = ..., tz: str | tzinfo | int | None = ..., normalize: bool = ..., name: Hashable | None = ..., inclusive: Literal['both', 'neither'] | Literal['left', 'right'] = ..., unit: Literal['s', 'ms', 'us', 'ns'] | None = ...) -> DatetimeIndex
- python/pyspark/pandas/namespace.py:1920: note:     def date_range(*, end: str | date | datetime | datetime64[date | int | None] | Timestamp, periods: int, freq: str | timedelta | Timedelta | BaseOffset | None = ..., tz: str | tzinfo | int | None = ..., normalize: bool = ..., name: Hashable | None = ..., inclusive: Literal['both', 'neither'] | Literal['left', 'right'] = ..., unit: Literal['s', 'ms', 'us', 'ns'] | None = ...) -> DatetimeIndex
+ python/pyspark/pandas/namespace.py:1920: note:     def date_range(*, end: str | date | datetime[Any] | datetime64[date | int | None] | Timestamp, periods: int, freq: str | timedelta | Timedelta | BaseOffset | None = ..., tz: str | tzinfo | int | None = ..., normalize: bool = ..., name: Hashable | None = ..., inclusive: Literal['both', 'neither'] | Literal['left', 'right'] = ..., unit: Literal['s', 'ms', 'us', 'ns'] | None = ...) -> DatetimeIndex
- python/pyspark/pandas/indexes/base.py:2244: error: Incompatible return value type (got "str | bytes | date | timedelta | datetime64[date | int | None] | <7 more items>", expected "int | float | bool | str | bytes | Decimal | date | datetime | None")  [return-value]
+ python/pyspark/pandas/indexes/base.py:2244: error: Incompatible return value type (got "str | bytes | date | timedelta | datetime64[date | int | None] | <7 more items>", expected "int | float | bool | str | bytes | Decimal | date | datetime[Any] | None")  [return-value]

freqtrade (https://github.com/freqtrade/freqtrade)
- freqtrade/data/metrics.py:242: error: Argument 1 to "abs" has incompatible type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "SupportsAbs[object]"  [arg-type]
+ freqtrade/data/metrics.py:242: error: Argument 1 to "abs" has incompatible type "str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "SupportsAbs[object]"  [arg-type]
- freqtrade/data/metrics.py:243: error: Argument "high_date" to "DrawDownResult" has incompatible type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "Timestamp"  [arg-type]
+ freqtrade/data/metrics.py:243: error: Argument "high_date" to "DrawDownResult" has incompatible type "str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "Timestamp"  [arg-type]
- freqtrade/data/metrics.py:244: error: Argument "low_date" to "DrawDownResult" has incompatible type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "Timestamp"  [arg-type]
+ freqtrade/data/metrics.py:244: error: Argument "low_date" to "DrawDownResult" has incompatible type "str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "Timestamp"  [arg-type]
- freqtrade/data/metrics.py:245: error: Argument "high_value" to "DrawDownResult" has incompatible type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "float"  [arg-type]
+ freqtrade/data/metrics.py:245: error: Argument "high_value" to "DrawDownResult" has incompatible type "str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "float"  [arg-type]
- freqtrade/data/metrics.py:246: error: Argument "low_value" to "DrawDownResult" has incompatible type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "float"  [arg-type]
+ freqtrade/data/metrics.py:246: error: Argument "low_value" to "DrawDownResult" has incompatible type "str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "float"  [arg-type]
- freqtrade/data/metrics.py:247: error: Argument "relative_account_drawdown" to "DrawDownResult" has incompatible type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "float"  [arg-type]
+ freqtrade/data/metrics.py:247: error: Argument "relative_account_drawdown" to "DrawDownResult" has incompatible type "str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "float"  [arg-type]
- freqtrade/data/metrics.py:249: error: Argument "current_high_date" to "DrawDownResult" has incompatible type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "Timestamp"  [arg-type]
+ freqtrade/data/metrics.py:249: error: Argument "current_high_date" to "DrawDownResult" has incompatible type "str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "Timestamp"  [arg-type]
- freqtrade/data/converter/orderflow.py:116: error: Incompatible types in assignment (expression has type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]", variable has type "datetime")  [assignment]
+ freqtrade/data/converter/orderflow.py:116: error: Incompatible types in assignment (expression has type "str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]", variable has type "datetime[Any]")  [assignment]
- freqtrade/data/converter/orderflow.py:142: error: Incompatible types in assignment (expression has type "dict[Hashable, dict[Hashable, Any]]", target has type "str | bytes | date | datetime | timedelta | <19 more items> | None")  [assignment]
+ freqtrade/data/converter/orderflow.py:142: error: Incompatible types in assignment (expression has type "dict[Hashable, dict[Hashable, Any]]", target has type "str | bytes | date | datetime[Any] | timedelta | <19 more items> | None")  [assignment]
- freqtrade/data/converter/orderflow.py:175: note:     def __rsub__(self, datetime | Timestamp | datetime64[date | int | None], /) -> Timestamp
+ freqtrade/data/converter/orderflow.py:175: note:     def __rsub__(self, datetime[Any] | Timestamp | datetime64[date | int | None], /) -> Timestamp
- freqtrade/data/converter/orderflow.py:175: note:     def __sub__(self, datetime, /) -> Never
+ freqtrade/data/converter/orderflow.py:175: note:     def __sub__(self, datetime[Any], /) -> Never
+ freqtrade/data/converter/orderflow.py:175: note:     def __sub__(self, datetime[tzinfo] | datetime[tzinfo | None], /) -> timedelta
- freqtrade/data/converter/orderflow.py:175: note:     def __sub__(self, datetime, /) -> timedelta
+ freqtrade/data/converter/orderflow.py:175: note:     def __sub__(self, datetime[None] | datetime[tzinfo | None], /) -> timedelta
- freqtrade/data/converter/orderflow.py:175: note:     def __sub__(self, timedelta, /) -> datetime
+ freqtrade/data/converter/orderflow.py:175: note:     def __sub__(self, timedelta, /) -> datetime[Any]
- freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("timedelta" and "datetime")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("timedelta" and "datetime[Any]")  [operator]
- freqtrade/data/converter/orderflow.py:175: error: No overload variant of "__sub__" of "timedelta64" matches argument type "datetime"  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: No overload variant of "__sub__" of "timedelta64" matches argument type "datetime[Any]"  [operator]
- freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("bool" and "datetime")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("bool" and "datetime[Any]")  [operator]
- freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("int" and "datetime")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("int" and "datetime[Any]")  [operator]
- freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("float" and "datetime")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("float" and "datetime[Any]")  [operator]
- freqtrade/data/converter/orderflow.py:175: note:     def __sub__(self, datetime | datetime64[date | int | None], /) -> Timedelta
+ freqtrade/data/converter/orderflow.py:175: note:     def __sub__(self, datetime[Any] | datetime64[date | int | None], /) -> Timedelta
- freqtrade/data/converter/orderflow.py:175: error: No overload variant of "__sub__" of "Timedelta" matches argument type "datetime"  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: No overload variant of "__sub__" of "Timedelta" matches argument type "datetime[Any]"  [operator]
- freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("complex" and "datetime")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("complex" and "datetime[Any]")  [operator]
- freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("integer[Any]" and "datetime")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("integer[Any]" and "datetime[Any]")  [operator]
- freqtrade/data/converter/orderflow.py:175: error: No overload variant of "__sub__" of "floating" matches argument type "datetime"  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: No overload variant of "__sub__" of "floating" matches argument type "datetime[Any]"  [operator]
- freqtrade/data/converter/orderflow.py:175: error: No overload variant of "__sub__" of "complexfloating" matches argument type "datetime"  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: No overload variant of "__sub__" of "complexfloating" matches argument type "datetime[Any]"  [operator]
- freqtrade/data/converter/converter.py:108: error: Argument 1 has incompatible type "dict[str, str]"; expected "Callable[[DataFrame], str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] | Callable[[DataFrame], Series[Any]] | Callable[[DataFrame], DataFrame] | ufunc | str | list[Callable[[DataFrame], str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] | Callable[[DataFrame], Series[Any]] | Callable[[DataFrame], DataFrame] | ufunc | str] | Mapping[Hashable, Callable[[DataFrame], str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] | Callable[[DataFrame], Series[Any]] | Callable[[DataFrame], DataFrame] | ufunc | str | list[Callable[[DataFrame], str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] | Callable[[DataFrame], Series[Any]] | Callable[[DataFrame], DataFrame] | ufunc | str]] | None"  [arg-type]
+ freqtrade/data/converter/converter.py:108: error: Argument 1 has incompatible type "dict[str, str]"; expected "Callable[[DataFrame], str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] | Callable[[DataFrame], Series[Any]] | Callable[[DataFrame], DataFrame] | ufunc | str | list[Callable[[DataFrame], str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] | Callable[[DataFrame], Series[Any]] | Callable[[DataFrame], DataFrame] | ufunc | str] | Mapping[Hashable, Callable[[DataFrame], str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] | Callable[[DataFrame], Series[Any]] | Callable[[DataFrame], DataFrame] | ufunc | str | list[Callable[[DataFrame], str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] | Callable[[DataFrame], Series[Any]] | Callable[[DataFrame], DataFrame] | ufunc | str]] | None"  [arg-type]
- freqtrade/optimize/optimize_reports/optimize_reports.py:341: error: Argument 1 to "int" has incompatible type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc"  [arg-type]
+ freqtrade/optimize/optimize_reports/optimize_reports.py:341: error: Argument 1 to "int" has incompatible type "str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc"  [arg-type]
- freqtrade/optimize/optimize_reports/optimize_reports.py:342: error: Argument 1 to "int" has incompatible type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc"  [arg-type]
+ freqtrade/optimize/optimize_reports/optimize_reports.py:342: error: Argument 1 to "int" has incompatible type "str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"; expected "str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc"  [arg-type]
- freqtrade/strategy/strategy_helper.py:102: error: Invalid index type "tuple[str | bytes | date | timedelta | datetime64[date | int | None] | <7 more items>, str]" for "_AtIndexerFrame"; expected type "tuple[int | str | str_ | Timestamp | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...] | Callable[[DataFrame], Never], int | str | str_ | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...]]"  [index]
+ freqtrade/strategy/strategy_helper.py:102: error: Invalid index type "tuple[str | bytes | date | timedelta | datetime64[date | int | None] | <7 more items>, str]" for "_AtIndexerFrame"; expected type "tuple[int | str | str_ | Timestamp | tuple[str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...] | Callable[[DataFrame], Never], int | str | str_ | tuple[str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...]]"  [index]
- freqtrade/strategy/strategy_helper.py:107: note:     def __sub__(self, datetime, /) -> Never
+ freqtrade/strategy/strategy_helper.py:107: note:     def __sub__(self, datetime[Any], /) -> Never
- freqtrade/strategy/strategy_helper.py:108: note:     def __sub__(self, datetime, /) -> Never
+ freqtrade/strategy/strategy_helper.py:108: note:     def __sub__(self, datetime[Any], /) -> Never
- freqtrade/plot/plotting.py:187: error: Invalid index type "tuple[datetime, str]" for "_LocIndexerFrame[DataFrame]"; expected type "slice[Any, Any, Any] | ndarray[tuple[Any, ...], dtype[integer[Any]]] | Index[Any] | list[int] | Series[int] | <6 more items>"  [index]
+ freqtrade/plot/plotting.py:187: error: Invalid index type "tuple[datetime[Any], str]" for "_LocIndexerFrame[DataFrame]"; expected type "slice[Any, Any, Any] | ndarray[tuple[Any, ...], dtype[integer[Any]]] | Index[Any] | list[int] | Series[int] | <6 more items>"  [index]
- freqtrade/plot/plotting.py:188: error: Invalid index type "tuple[datetime, str]" for "_LocIndexerFrame[DataFrame]"; expected type "slice[Any, Any, Any] | ndarray[tuple[Any, ...], dtype[integer[Any]]] | Index[Any] | list[int] | Series[int] | <6 more items>"  [index]
+ freqtrade/plot/plotting.py:188: error: Invalid index type "tuple[datetime[Any], str]" for "_LocIndexerFrame[DataFrame]"; expected type "slice[Any, Any, Any] | ndarray[tuple[Any, ...], dtype[integer[Any]]] | Index[Any] | list[int] | Series[int] | <6 more items>"  [index]
- freqtrade/templates/FreqaiExampleStrategy.py:244: note:     def [ScalarT: str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] __setitem__(self, Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | str_ | <9 more items>, str | bytes | date | datetime | timedelta | <19 more items> | None, /) -> None
+ freqtrade/templates/FreqaiExampleStrategy.py:244: note:     def [ScalarT: str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] __setitem__(self, Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | str_ | <9 more items>, str | bytes | date | datetime[Any] | timedelta | <19 more items> | None, /) -> None
- freqtrade/templates/FreqaiExampleStrategy.py:244: note:     def __setitem__(self, tuple[tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | list[Any] | slice[Any, Any, Any] | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...], ...], Hashable], str | bytes | date | datetime | timedelta | <18 more items> | None, /) -> None
+ freqtrade/templates/FreqaiExampleStrategy.py:244: note:     def __setitem__(self, tuple[tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | list[Any] | slice[Any, Any, Any] | tuple[str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...], ...], Hashable], str | bytes | date | datetime[Any] | timedelta | <18 more items> | None, /) -> None
- freqtrade/templates/FreqaiExampleStrategy.py:245: error: Unsupported left operand type for & ("tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | list[Any] | slice[Any, Any, Any] | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...], ...]")  [operator]
+ freqtrade/templates/FreqaiExampleStrategy.py:245: error: Unsupported left operand type for & ("tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | list[Any] | slice[Any, Any, Any] | tuple[str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...], ...]")  [operator]
- freqtrade/templates/FreqaiExampleStrategy.py:254: note:     def [ScalarT: str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] __setitem__(self, Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | str_ | <9 more items>, str | bytes | date | datetime | timedelta | <19 more items> | None, /) -> None
+ freqtrade/templates/FreqaiExampleStrategy.py:254: note:     def [ScalarT: str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] __setitem__(self, Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | str_ | <9 more items>, str | bytes | date | datetime[Any] | timedelta | <19 more items> | None, /) -> None
- freqtrade/templates/FreqaiExampleStrategy.py:254: note:     def __setitem__(self, tuple[tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | list[Any] | slice[Any, Any, Any] | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...], ...], Hashable], str | bytes | date | datetime | timedelta | <18 more items> | None, /) -> None
+ freqtrade/templates/FreqaiExampleStrategy.py:254: note:     def __setitem__(self, tuple[tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | list[Any] | slice[Any, Any, Any] | tuple[str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...], ...], Hashable], str | bytes | date | datetime[Any] | timedelta | <18 more items> | None, /) -> None
- freqtrade/templates/FreqaiExampleStrategy.py:255: error: Unsupported left operand type for & ("tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | list[Any] | slice[Any, Any, Any] | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...], ...]")  [operator]
+ freqtrade/templates/FreqaiExampleStrategy.py:255: error: Unsupported left operand type for & ("tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | list[Any] | slice[Any, Any, Any] | tuple[str | bytes | date | datetime[Any] | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...], ...]")  [operator]

tornado (https://github.com/tornadoweb/tornado)
+ tornado/test/locale_test.py:100: error: Unsupported operand types for - ("object" and "timedelta")  [operator]
+ tornado/test/locale_test.py:100: error: Argument 1 to "format_date" of "Locale" has incompatible type "timedelta"; expected "int | float | datetime[Any]"  [arg-type]
+ tornado/test/locale_test.py:106: error: Unsupported operand types for - ("object" and "timedelta")  [operator]
+ tornado/test/locale_test.py:106: error: Argument 1 to "format_date" of "Locale" has incompatible type "timedelta"; expected "int | float | datetime[Any]"  [arg-type]
+ tornado/test/locale_test.py:112: error: Unsupported operand types for - ("object" and "timedelta")  [operator]
+ tornado/test/locale_test.py:112: error: Argument 1 to "format_date" of "Locale" has incompatible type "timedelta"; expected "int | float | datetime[Any]"  [arg-type]
+ tornado/test/locale_test.py:119: error: Unsupported operand types for - ("object" and "timedelta")  [operator]
+ tornado/test/locale_test.py:119: error: Argument 1 to "format_date" of "Locale" has incompatible type "timedelta"; expected "int | float | datetime[Any]"  [arg-type]
+ tornado/test/locale_test.py:126: error: Unsupported operand types for - ("object" and "timedelta")  [operator]
+ tornado/test/locale_test.py:126: error: Incompatible types in assignment (expression has type "timedelta", variable has type "datetime[None]")  [assignment]
+ tornado/test/locale_test.py:132: error: Unsupported operand types for - ("object" and "timedelta")  [operator]
+ tornado/test/locale_test.py:132: error: Incompatible types in assignment (expression has type "timedelta", variable has type "datetime[None]")  [assignment]
+ tornado/test/locale_test.py:138: error: Unsupported operand types for - ("object" and "timedelta")  [operator]
+ tornado/test/locale_test.py:138: error: Incompatible types in assignment (expression has type "timedelta", variable has type "datetime[None]")  [assignment]

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ bson/json_util.py:928: error: Unused "type: ignore" comment  [unused-ignore]
+ pymongo/ocsp_cache.py:92: error: Incompatible types in assignment (expression has type "datetime[None]", variable has type "datetime[tzinfo]")  [assignment]
+ pymongo/ocsp_cache.py:126: error: Incompatible types in assignment (expression has type "datetime[None]", variable has type "datetime[tzinfo]")  [assignment]
+ pymongo/ocsp_support.py:283: error: Incompatible types in assignment (expression has type "datetime[None]", variable has type "datetime[tzinfo]")  [assignment]

openlibrary (https://github.com/internetarchive/openlibrary)
+ openlibrary/tests/core/test_unmarshal.py:32: error: Unused "type: ignore" comment  [unused-ignore]
+ openlibrary/tests/core/test_unmarshal.py: note: In function "parse_datetime":
+ openlibrary/tests/core/test_unmarshal.py:32: error: No overload variant of "datetime" matches argument type "Generator[int, None, None]"  [call-overload]
+ openlibrary/tests/core/test_unmarshal.py:32: note: Error code "call-overload" not covered by "type: ignore" comment
+ openlibrary/tests/core/test_unmarshal.py:32: note: Possible overload variants:
+ openlibrary/tests/core/test_unmarshal.py:32: note:     def [_TzInfoT: tzinfo | None] __new__(cls, year: SupportsIndex, month: SupportsIndex, day: SupportsIndex, hour: SupportsIndex = ..., minute: SupportsIndex = ..., second: SupportsIndex = ..., microsecond: SupportsIndex = ..., tzinfo: None = ..., *, fold: int = ...) -> datetime[None]
+ openlibrary/tests/core/test_unmarshal.py:32: note:     def [_TzInfoT: tzinfo | None] __new__(cls, year: SupportsIndex, month: SupportsIndex, day: SupportsIndex, hour: SupportsIndex = ..., minute: SupportsIndex = ..., second: SupportsIndex = ..., microsecond: SupportsIndex = ..., *, tzinfo: tzinfo, fold: int = ...) -> datetime[tzinfo]
+ openlibrary/tests/core/test_unmarshal.py:32: note:     def [_TzInfoT: tzinfo | None] __new__(cls, year: SupportsIndex, month: SupportsIndex, day: SupportsIndex, hour: SupportsIndex, minute: SupportsIndex, second: SupportsIndex, microsecond: SupportsIndex, tzinfo: tzinfo, *, fold: int = ...) -> datetime[tzinfo]

bokeh (https://github.com/bokeh/bokeh)
- src/bokeh/util/serialization.py:168:1: error: Argument 1 to "convert_datetime_type" becomes "Any | Any | Any | datetime | date | time | datetime64[date | int | None]" due to an unfollowed import  [no-any-unimported]
+ src/bokeh/util/serialization.py:168:1: error: Argument 1 to "convert_datetime_type" becomes "Any | Any | Any | datetime[Any] | date | time | datetime64[date | int | None]" due to an unfollowed import  [no-any-unimported]

dulwich (https://github.com/dulwich/dulwich)
+ dulwich/approxidate.py:98: error: Incompatible types in assignment (expression has type "datetime[tzinfo | None]", variable has type "datetime[None]")  [assignment]

alerta (https://github.com/alerta/alerta)
- alerta/models/key.py:24: error: Incompatible default for argument "expire_time" (default has type "None", argument has type "datetime")  [assignment]
+ alerta/models/key.py:24: error: Incompatible default for argument "expire_time" (default has type "None", argument has type "datetime[Any]")  [assignment]
- alerta/models/key.py:54: error: Argument "expire_time" to "ApiKey" has incompatible type "datetime | None"; expected "datetime"  [arg-type]
+ alerta/models/key.py:54: error: Argument "expire_time" to "ApiKey" has incompatible type "datetime[Any] | None"; expected "datetime[Any]"  [arg-type]
- alerta/models/key.py:93: error: Argument "expire_time" to "ApiKey" has incompatible type "Any | None"; expected "datetime"  [arg-type]
+ alerta/models/key.py:93: error: Argument "expire_time" to "ApiKey" has incompatible type "Any | None"; expected "datetime[Any]"  [arg-type]
- alerta/models/heartbeat.py:28: error: Incompatible default for argument "create_time" (default has type "None", argument has type "datetime")  [assignment]
+ alerta/models/heartbeat.py:28: error: Incompatible default for argument "create_time" (default has type "None", argument has type "datetime[Any]")  [assignment]
- alerta/models/heartbeat.py:88: error: Argument "create_time" to "Heartbeat" has incompatible type "datetime | None"; expected "datetime"  [arg-type]
+ alerta/models/heartbeat.py:88: error: Argument "create_time" to "Heartbeat" has incompatible type "datetime[Any] | None"; expected "datetime[Any]"  [arg-type]
- alerta/models/heartbeat.py:124: error: Argument "create_time" to "Heartbeat" has incompatible type "Any | None"; expected "datetime"  [arg-type]
+ alerta/models/heartbeat.py:124: error: Argument "create_time" to "Heartbeat" has incompatible type "Any | None"; expected "datetime[Any]"  [arg-type]

spack (https://github.com/spack/spack)
+ lib/spack/spack/llnl/util/lang.py:640: error: Incompatible types in assignment (expression has type "Callable[[Any], datetime[Any] | datetime[None]]", target has type "Callable[[Any], datetime[tzinfo | None]]")  [assignment]

psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/types/datetime.py:582: error: Incompatible types in assignment (expression has type "datetime[None]", variable has type "datetime[tzinfo]")  [assignment]

apprise (https://github.com/caronc/apprise)
- apprise/asset.py:283: error: Incompatible types in assignment (expression has type "tzinfo | None", variable has type "None")  [assignment]
- apprise/persistent_store.py:128: error: Incompatible types in assignment (expression has type "datetime", variable has type "None")  [assignment]
+ apprise/persistent_store.py:128: error: Incompatible types in assignment (expression has type "datetime[Any]", variable has type "None")  [assignment]
- apprise/persistent_store.py:136: error: Incompatible types in assignment (expression has type "datetime", variable has type "None")  [assignment]
+ apprise/persistent_store.py:136: error: Incompatible types in assignment (expression has type "datetime[tzinfo]", variable has type "None")  [assignment]
- apprise/persistent_store.py:139: error: Incompatible types in assignment (expression has type "datetime", variable has type "None")  [assignment]
+ apprise/persistent_store.py:139: error: Incompatible types in assignment (expression has type "datetime[tzinfo]", variable has type "None")  [assignment]
- apprise/persistent_store.py:1427: error: Incompatible types in assignment (expression has type "datetime | int", variable has type "int | float | None")  [assignment]
+ apprise/persistent_store.py:1427: error: Incompatible types in assignment (expression has type "datetime[None] | int", variable has type "int | float | None")  [assignment]
- apprise/persistent_store.py:1525: error: Unsupported operand types for > ("datetime" and "None")  [operator]
+ apprise/persistent_store.py:1525: error: No overload variant of "__gt__" of "datetime" matches argument type "None"  [operator]
+ apprise/persistent_store.py:1525: note: Possible overload variants:
+ apprise/persistent_store.py:1525: note:     def __gt__(self, datetime[None] | datetime[tzinfo | None], /) -> bool
+ apprise/persistent_store.py:1525: note:     def __gt__(self, datetime[Any], /) -> Never
- apprise/persistent_store.py:1525: error: Unsupported operand types for < ("int" and "datetime")  [operator]
+ apprise/persistent_store.py:1525: error: Unsupported operand types for < ("int" and "datetime[None]")  [operator]
- apprise/persistent_store.py:1525: error: Unsupported operand types for < ("float" and "datetime")  [operator]
+ apprise/persistent_store.py:1525: error: Unsupported operand types for < ("float" and "datetime[None]")  [operator]

core (https://github.com/home-assistant/core)
- homeassistant/util/dt.py:230: error: Returning Any from function declared to return "datetime | None"  [no-any-return]
+ homeassistant/util/dt.py:230: error: Returning Any from function declared to return "datetime[Any] | None"  [no-any-return]
- homeassistant/core.py:1902: error: Returning Any from function declared to return "ReadOnlyDict[str, datetime | Collection[Any]]"  [no-any-return]
+ homeassistant/core.py:1902: error: Returning Any from function declared to return "ReadOnlyDict[str, datetime[Any] | Collection[Any]]"  [no-any-return]
+ homeassistant/components/recorder/models/state.py:77: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/recorder/models/state.py:89: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/helpers/sun.py:150: error: Returning Any from function declared to return "bool"  [no-any-return]
+ homeassistant/helpers/condition.py:783: error: Returning Any from function declared to return "bool"  [no-any-return]
- homeassistant/components/recorder/util.py:378: error: Returning Any from function declared to return "datetime | None"  [no-any-return]
+ homeassistant/components/recorder/util.py:378: error: Returning Any from function declared to return "datetime[Any] | None"  [no-any-return]
+ homeassistant/components/alexa/auth.py:113: error: Returning Any from function declared to return "bool"  [no-any-return]
+ homeassistant/components/calendar/__init__.py:503: error: Returning Any from function declared to return "bool"  [no-any-return]
+ homeassistant/components/tod/binary_sensor.py:141: error: Returning Any from function declared to return "bool"  [no-any-return]
+ homeassistant/components/sun/condition.py:90: error: Returning Any from function declared to return "bool"  [no-any-return]
+ homeassistant/components/jewish_calendar/services.py:58: error: Returning Any from function declared to return "bool"  [no-any-return]
+ homeassistant/components/history_stats/helpers.py:89: error: Returning Any from function declared to return "float"  [no-any-return]
+ homeassistant/components/evohome/storage.py:98: error: Incompatible types in assignment (expression has type "datetime[tzinfo | None]", variable has type "datetime[tzinfo]")  [assignment]
- homeassistant/components/evohome/storage.py:98: error: Argument 1 to "fromisoformat" of "date" has incompatible type "object"; expected "str"  [arg-type]
+ homeassistant/components/evohome/storage.py:98: error: Argument 1 to "fromisoformat" of "datetime" has incompatible type "object"; expected "str"  [arg-type]
+ homeassistant/components/calendar/trigger.py:71: error: Returning Any from function declared to return "bool"  [no-any-return]
- homeassistant/components/russound_rio/media_player.py:167: error: Returning Any from function declared to return "datetime"  [no-any-return]
+ homeassistant/components/russound_rio/media_player.py:167: error: Returning Any from function declared to return "datetime[Any]"  [no-any-return]
+ homeassistant/components/nordpool/coordinator.py:67: error: Incompatible types in assignment (expression has type "datetime[tzinfo]", variable has type "datetime[None]")  [assignment]
- homeassistant/components/nest/camera.py:229: error: Returning Any from function declared to return "datetime | None"  [no-any-return]
+ homeassistant/components/nest/camera.py:229: error: Returning Any from function declared to return "datetime[Any] | None"  [no-any-return]
- homeassistant/components/nest/camera.py:261: error: Returning Any from function declared to return "datetime | None"  [no-any-return]
+ homeassistant/components/nest/camera.py:261: error: Returning Any from function declared to return "datetime[Any] | None"  [no-any-return]
- homeassistant/components/jewish_calendar/sensor.py:304: error: Returning Any from function declared to return "datetime | None"  [no-any-return]
+ homeassistant/components/jewish_calendar/sensor.py:304: error: Returning Any from function declared to return "datetime[Any] | None"  [no-any-return]
- homeassistant/components/ecowitt/sensor.py:323: error: Returning Any from function declared to return "str | int | float | None | datetime"  [no-any-return]
+ homeassistant/components/ecowitt/sensor.py:323: error: Returning Any from function declared to return "str | int | float | None | datetime[Any]"  [no-any-return]
- homeassistant/components/discovergy/sensor.py:36: error: Returning Any from function declared to return "datetime | float | None"  [no-any-return]
+ homeassistant/components/discovergy/sensor.py:36: error: Returning Any from function declared to return "datetime[Any] | float | None"  [no-any-return]
+ homeassistant/components/derivative/sensor.py:240: error: Returning Any from function declared to return "float"  [no-any-return]
- homeassistant/components/cambridge_audio/media_player.py:179: error: Returning Any from function declared to return "datetime"  [no-any-return]
+ homeassistant/components/cambridge_audio/media_player.py:179: error: Returning Any from function declared to return "datetime[Any]"  [no-any-return]
- homeassistant/components/vodafone_station/sensor.py:54: error: Returning Any from function declared to return "datetime"  [no-any-return]
+ homeassistant/components/vodafone_station/sensor.py:54: error: Returning Any from function declared to return "datetime[Any]"  [no-any-return]
- homeassistant/components/vallox/sensor.py:71: error: Returning Any from function declared to return "str | int | float | None | datetime"  [no-any-return]
+ homeassistant/components/vallox/sensor.py:71: error: Returning Any from function declared to return "str | int | float | None | datetime[Any]"  [no-any-return]
+ homeassistant/components/statistics/sensor.py:1045: error: Incompatible types in assignment (expression has type "datetime[tzinfo]", variable has type "datetime[None]")  [assignment]
+ homeassistant/components/sensor/recorder.py:162: error: Returning Any from function declared to return "float"  [no-any-return]
+ homeassistant/components/local_calendar/calendar.py:220: note:     def __sub__(self, datetime[tzinfo] | datetime[tzinfo | None], /) -> timedelta
+ homeassistant/components/local_calendar/calendar.py:220: note:     def __sub__(self, datetime[None] | datetime[tzinfo | None], /) -> timedelta
- homeassistant/components/local_calendar/calendar.py:220: note:     def __sub__(self, datetime, /) -> timedelta
+ homeassistant/components/local_calendar/calendar.py:220: note:     def __sub__(self, datetime[Any], /) -> Never
- homeassistant/components/local_calendar/calendar.py:220: note:     def __sub__(self, timedelta, /) -> datetime
+ homeassistant/components/local_calendar/calendar.py:220: note:     def __sub__(self, timedelta, /) -> datetime[Any]
- homeassistant/components/alexa_devices/sensor.py:154: error: Returning Any from function declared to return "str | int | float | None | datetime"  [no-any-return]
+ homeassistant/components/alexa_devices/sensor.py:154: error: Returning Any from function declared to return "str | int | float | None | datetime[Any]"  [no-any-return]
- homeassistant/components/alexa_devices/sensor.py:156: error: Returning Any from function declared to return "str | int | float | None | datetime"  [no-any-return]
+ homeassistant/components/alexa_devices/sensor.py:156: error: Returning Any from function declared to return "str | int | float | None | datetime[Any]"  [no-any-return]
- homeassistant/components/unifiprotect/sensor.py:97: error: Returning Any from function declared to return "datetime | None"  [no-any-return]
+ homeassistant/components/unifiprotect/sensor.py:97: error: Returning Any from function declared to return "datetime[Any] | None"  [no-any-return]
+ homeassistant/components/onvif/device.py:292: error: Need type annotation for "dt_diff"  [var-annotated]
- homeassistant/components/knx/datetime.py:97: error: Returning Any from function declared to return "datetime | None"  [no-any-return]
+ homeassistant/components/knx/datetime.py:97: error: Returning Any from function declared to return "datetime[Any] | None"  [no-any-return]
- homeassistant/components/habitica/calendar.py:101: error: Redundant cast to "list[datetime]"  [redundant-cast]
+ homeassistant/components/habitica/calendar.py:101: error: Redundant cast to "list[datetime[Any]]"  [redundant-cast]
- homeassistant/components/roku/media_player.py:242: error: Returning Any from function declared to return "datetime | None"  [no-any-return]
+ homeassistant/components/roku/media_player.py:242: error: Returning Any from function declared to return "datetime[Any] | None"  [no-any-return]
- homeassistant/components/esphome/sensor.py:110: error: Returning Any from function declared to return "datetime | int | float | None"  [no-any-return]
+ homeassistant/components/esphome/sensor.py:110: error: Returning Any from function declared to return "datetime[Any] | int | float | None"  [no-any-return]
- homeassistant/components/esphome/sensor.py:139: error: Returning Any from function declared to return "str | datetime | date | None"  [no-any-return]
+ homeassistant/components/esphome/sensor.py:139: error: Returning Any from function declared to return "str | datetime[Any] | date | None"  [no-any-return]
- homeassistant/components/dlna_dmr/media_player.py:933: error: Returning Any from function declared to return "datetime | None"  [no-any-return]
+ homeassistant/components/dlna_dmr/media_player.py:933: error: Returning Any from function declared to return "datetime[Any] | None"  [no-any-return]

koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/generic.py:82: error: Returning Any from function declared to return "bool"  [no-any-return]
+ koda_validate/generic.py:84: error: Returning Any from function declared to return "bool"  [no-any-return]
+ koda_validate/generic.py:94: error: Returning Any from function declared to return "bool"  [no-any-return]
+ koda_validate/generic.py:96: error: Returning Any from function declared to return "bool"  [no-any-return]

materialize (https://github.com/MaterializeInc/materialize)
- misc/python/materialize/scratch.py:74: error: Argument 1 to "fromtimestamp" of "datetime" has incompatible type "str"; expected "float"  [arg-type]
+ misc/python/materialize/scratch.py:74: error: No overload variant of "fromtimestamp" of "datetime" matches argument type "str"  [call-overload]
+ misc/python/materialize/scratch.py:74: note: Possible overload variants:
+ misc/python/materialize/scratch.py:74: note:     def [_TzInfoT: tzinfo | None] fromtimestamp(cls, timestamp: float, tz: None = ...) -> datetime[None]
+ misc/python/materialize/scratch.py:74: note:     def [_TzInfoT: tzinfo | None] fromtimestamp(cls, timestamp: float, tz: tzinfo) -> datetime[tzinfo]
- misc/python/materialize/parallel_workload/parallel_workload.py:413: error: Incompatible types in assignment (expression has type "datetime", variable has type "float")  [assignment]
+ misc/python/materialize/parallel_workload/parallel_workload.py:413: error: Incompatible types in assignment (expression has type "datetime[None]", variable has type "float")  [assignment]
- misc/python/materialize/parallel_workload/parallel_workload.py:414: error: Unsupported operand types for < ("datetime" and "float")  [operator]
+ misc/python/materialize/parallel_workload/parallel_workload.py:414: error: No overload variant of "__lt__" of "datetime" matches argument type "float"  [operator]
+ misc/python/materialize/parallel_workload/parallel_workload.py:414: note: Possible overload variants:
+ misc/python/materialize/parallel_workload/parallel_workload.py:414: note:     def __lt__(self, datetime[None] | datetime[tzinfo | None], /) -> bool
+ misc/python/materialize/parallel_workload/parallel_workload.py:414: note:     def __lt__(self, datetime[Any], /) -> Never

pandas (https://github.com/pandas-dev/pandas)
+ pandas/_libs/tslibs/timestamps.pyi:146: error: Signatures of "__le__" of "Timestamp" and "__ge__" of "datetime[Any]" are unsafely overlapping  [misc]
+ pandas/_libs/tslibs/timestamps.pyi:146: note: Error code "misc" not covered by "type: ignore" comment
+ pandas/_libs/tslibs/timestamps.pyi:147: error: Signatures of "__lt__" of "Timestamp" and "__gt__" of "datetime[Any]" are unsafely overlapping  [misc]
+ pandas/_libs/tslibs/timestamps.pyi:147: note: Error code "misc" not covered by "type: ignore" comment
+ pandas/_libs/tslibs/timestamps.pyi:148: error: Signatures of "__ge__" of "Timestamp" and "__le__" of "datetime[Any]" are unsafely overlapping  [misc]
+ pandas/_libs/tslibs/timestamps.pyi:148: note: Error code "misc" not covered by "type: ignore" comment
+ pandas/_libs/tslibs/timestamps.pyi:149: error: Signatures of "__gt__" of "Timestamp" and "__lt__" of "datetime[Any]" are unsafely overlapping  [misc]
+ pandas/_libs/tslibs/timestamps.pyi:149: note: Error code "misc" not covered by "type: ignore" comment

Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/schedules.py:1094: error: Need type annotation for "result"  [var-annotated]
+ tanjun/schedules.py:1096: error: Statement is unreachable  [unreachable]

ibis (https://github.com/ibis-project/ibis)
- ibis/expr/types/temporal.py:1231: error: Argument "right" to "TimestampDelta" has incompatible type "datetime | ibis.expr.types.generic.Value"; expected "ibis.expr.operations.core.Value[Timestamp, Any]"  [arg-type]
+ ibis/expr/types/temporal.py:1231: error: Argument "right" to "TimestampDelta" has incompatible type "datetime[Any] | ibis.expr.types.generic.Value"; expected "ibis.expr.operations.core.Value[Timestamp, Any]"  [arg-type]
- ibis/expr/api.py:2435: error: Argument "start" to "TimestampRange" has incompatible type "Any | datetime | TimestampValue"; expected "Value[Timestamp, Any]"  [arg-type]
+ ibis/expr/api.py:2435: error: Argument "start" to "TimestampRange" has incompatible type "Any | datetime[Any] | TimestampValue"; expected "Value[Timestamp, Any]"  [arg-type]
- ibis/expr/api.py:2436: error: Argument "stop" to "TimestampRange" has incompatible type "Any | datetime | TimestampValue"; expected "Value[Timestamp, Any]"  [arg-type]
+ ibis/expr/api.py:2436: error: Argument "stop" to "TimestampRange" has incompatible type "Any | datetime[Any] | TimestampValue"; expected "Value[Timestamp, Any]"  [arg-type]
- ibis/backends/exasol/__init__.py:308: error: "datetime" has no attribute "tz_convert"  [attr-defined]
+ ibis/backends/exasol/__init__.py:308: error: "datetime[Any]" has no attribute "tz_convert"  [attr-defined]

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/_internal/schemas/validators.py:237: error: Item "None" of "tzinfo | None" has no attribute "name"  [union-attr]
- src/prefect/server/schemas/schedules.py:60: error: "datetime" has no attribute "in_tz"  [attr-defined]
+ src/prefect/server/schemas/schedules.py:60: error: "datetime[Any]" has no attribute "in_tz"  [attr-defined]
- src/prefect/server/schemas/schedules.py:66: error: "datetime" has no attribute "in_tz"  [attr-defined]
+ src/prefect/server/schemas/schedules.py:66: error: "datetime[Any]" has no attribute "in_tz"  [attr-defined]
- src/prefect/server/schemas/schedules.py:391: error: Item "datetime" of "datetime | Any" has no attribute "in_tz"  [union-attr]
+ src/prefect/server/schemas/schedules.py:391: error: Item "datetime[Any]" of "datetime[Any] | Any" has no attribute "in_tz"  [union-attr]
- src/prefect/server/schemas/schedules.py:406: error: Item "datetime" of "datetime | Any" has no attribute "tz"  [union-attr]
+ src/prefect/server/schemas/schedules.py:406: error: Item "datetime[Any]" of "datetime[Any] | Any" has no attribute "tz"  [union-attr]
- src/prefect/server/schemas/schedules.py:417: error: Item "datetime" of "datetime | Any" has no attribute "naive"  [union-attr]
+ src/prefect/server/schemas/schedules.py:417: error: Item "datetime[Any]" of "datetime[Any] | Any" has no attribute "naive"  [union-attr]
- src/prefect/server/schemas/schedules.py:606: error: Incompatible default for argument "start" (default has type "None", argument has type "datetime")  [assignment]
+ src/prefect/server/schemas/schedules.py:606: error: Incompatible default for argument "start" (default has type "None", argument has type "datetime[Any]")  [assignment]
- src/prefect/server/schemas/schedules.py:607: error: Incompatible default for argument "end" (default has type "None", argument has type "datetime")  [assignment]
+ src/prefect/server/schemas/schedules.py:607: error: Incompatible default for argument "end" (default has type "None", argument has type "datetime[Any]")  [assignment]
- src/prefect/_internal/compatibility/deprecated.py:106: error: Item "str" of "datetime | str | Any | None" has no attribute "strftime"  [union-attr]
+ src/prefect/_internal/compatibility/deprecated.py:106: error: Item "str" of "datetime[Any] | str | Any | None" has no attribute "strftime"  [union-attr]
- src/prefect/_internal/compatibility/deprecated.py:106: error: Item "None" of "datetime | str | Any | None" has no attribute "strftime"  [union-attr]
+ src/prefect/_internal/compatibility/deprecated.py:106: error: Item "None" of "datetime[Any] | str | Any | None" has no attribute "strftime"  [union-attr]
- src/prefect/server/schemas/responses.py:145: error: Incompatible types in assignment (expression has type "datetime", target has type "None")  [assignment]
+ src/prefect/server/schemas/responses.py:145: error: Incompatible types in assignment (expression has type "datetime[Any]", target has type "None")  [assignment]
- src/prefect/deployments/runner.py:619: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, str | Any | int | float | timedelta | datetime | None]"; expected "int | float | timedelta | None"  [arg-type]
+ src/prefect/deployments/runner.py:619: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, str | Any | int | float | timedelta | datetime[Any] | None]"; expected "int | float | timedelta | None"  [arg-type]
- src/prefect/deployments/runner.py:619: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, str | Any | int | float | timedelta | datetime | None]"; expected "datetime | str | None"  [arg-type]
+ src/prefect/deployments/runner.py:619: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, str | Any | int | float | timedelta | datetime[Any] | None]"; expected "datetime[Any] | str | None"  [arg-type]
- src/prefect/deployments/runner.py:619: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, str | Any | int | float | timedelta | datetime | None]"; expected "str | None"  [arg-type]
+ src/prefect/deployments/runner.py:619: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, str | Any | int | float | timedelta | datetime[Any] | None]"; expected "str | None"  [arg-type]
- src/prefect/testing/fixtures.py:210: error: "datetime" has no attribute "add"  [attr-defined]
+ src/prefect/testing/fixtures.py:210: error: "datetime[Any]" has no attribute "add"  [attr-defined]
- src/prefect/cli/work_queue.py:533: error: Unsupported operand types for > ("datetime" and "None")  [operator]
+ src/prefect/cli/work_queue.py:533: error: No overload variant of "__gt__" of "datetime" matches argument type "None"  [operator]
+ src/prefect/cli/work_queue.py:533: note: Possible overload variants:
+ src/prefect/cli/work_queue.py:533: note:     def __gt__(self, datetime[tzinfo] | datetime[tzinfo | None], /) -> bool
+ src/prefect/cli/work_queue.py:533: note:     def __gt__(self, datetime[None] | datetime[tzinfo | None], /) -> bool
+ src/prefect/cli/work_queue.py:533: note:     def __gt__(self, datetime[Any], /) -> Never
- src/prefect/cli/deployment.py:392: error: Value of "anchor_date" has incompatible type "datetime"; expected "str"  [typeddict-item]
+ src/prefect/cli/deployment.py:392: error: Value of "anchor_date" has incompatible type "datetime[Any]"; expected "str"  [typeddict-item]
- src/prefect/cli/deploy/_schedules.py:61: error: Argument 1 to "IntervalSchedule" has incompatible type "**dict[str, timedelta | Any | datetime]"; expected "timedelta"  [arg-type]
+ src/prefect/cli/deploy/_schedules.py:61: error: Argument 1 to "IntervalSchedule" has incompatible type "**dict[str, timedelta | Any | datetime[Any]]"; expected "timedelta"  [arg-type]
- src/prefect/cli/deploy/_schedules.py:61: error: Argument 1 to "IntervalSchedule" has incompatible type "**dict[str, timedelta | Any | datetime]"; expected "str | None"  [arg-type]
+ src/prefect/cli/deploy/_schedules.py:61: error: Argument 1 to "IntervalSchedule" has incompatible type "**dict[str, timedelta | Any | datetime[Any]]"; expected "str | None"  [arg-type]

DateType (https://github.com/glyph/DateType)
+ src/datetype/__init__.py:482: error: Argument 2 to "fromtimestamp" of "da

... (truncated 84 lines) ...

@srittau
Copy link
Collaborator Author

srittau commented Nov 10, 2025

Looking at some of the primer output (unfortunately, there's a lot of spam):

  • tornado: A bit unfortunate, since mypy infers {"aware": aware_dt, "naive": naive_dt} to be dict[str, object], instead of dict[str, datetime[...]].
  • mongo-python-driver, dulwich: Since aware and non-aware datetimes are now different objects, constructs like if now.tzinfo is None: now = make_tz_aware(now) won't work anymore in all cases, although I see that as a positive.
  • openlibrary: Needs update of type ignore.
  • homeassistant: Would be fixed by tightening the return annotation of their parse_datetime utility function to include the new tzinfo parameter.

Overall while I think that this generates quite a bit of churn, all that churn pays off by preventing really annoying and hard to spot tz awareness bugs.

@srittau srittau marked this pull request as ready for review November 10, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Safer types for datetime

2 participants