python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.34k stars 448 forks source link

dates.py syntax incompatibility with python versions older than 3.10 #1057

Closed MandarinoMcZumo closed 7 months ago

MandarinoMcZumo commented 10 months ago

Overview Description

Python syntax version incompatibility. The module dates.py applies the 3.10 union syntax. That is not compatible with older versions of python that the package should support. 3.10:

if TYPE_CHECKING:
    from typing_extensions import Literal, TypeAlias
    _Instant: TypeAlias = datetime.date | datetime.time | float | None
    _PredefinedTimeFormat: TypeAlias = Literal['full', 'long', 'medium', 'short']
    _Context: TypeAlias = Literal['format', 'stand-alone']
    _DtOrTzinfo: TypeAlias = datetime.datetime | datetime.tzinfo | str | int | datetime.time | None

older:

if TYPE_CHECKING:
    from typing_extensions import Literal, TypeAlias
    _Instant: TypeAlias = Union[datetime.date, datetime.time, float, None]
    _PredefinedTimeFormat: TypeAlias = Literal['full', 'long', 'medium', 'short']
    _Context: TypeAlias = Literal['format', 'stand-alone']
    _DtOrTzinfo: TypeAlias = Union[
        datetime.datetime, datetime.tzinfo, str, int, datetime.time, None]
akx commented 10 months ago

I'm not sure if there's an actual problem here – Mypy supports that syntax regardless of the Python version it's being run on, and that code will never be evaluated at runtime since it's in a if TYPE_CHECKING block?

akx commented 7 months ago

Closing since there is no additional information and we know Babel runs fine on versions older than 3.10 (for the time being).