From 971d6a30f53772e1b03efeca9f8ce0168e803034 Mon Sep 17 00:00:00 2001 From: Andrii Hrimov Date: Fri, 6 Jun 2025 05:04:00 +0200 Subject: [PATCH] Enhance `ZoneInfo.from_file` stub (#14221) Enhance ZoneInfo.from_file stub Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> --- stdlib/@tests/stubtest_allowlists/py312.txt | 2 -- stdlib/@tests/stubtest_allowlists/py313.txt | 2 -- stdlib/@tests/stubtest_allowlists/py314.txt | 2 -- stdlib/zoneinfo/__init__.pyi | 10 ++++++++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index c9bfee549..685a1bf41 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -7,8 +7,6 @@ # >= 3.12 # ======= -zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in different Python versions - # Initialized at runtime typing_extensions.TypeAliasType.__parameters__ typing_extensions.TypeAliasType.__value__ diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 7cd834acf..282b91348 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -12,8 +12,6 @@ # >= 3.12 # ======= -zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in different Python versions - # Initialized at runtime typing_extensions.TypeAliasType.__parameters__ typing_extensions.TypeAliasType.__value__ diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index e376fbe82..53dd45eac 100644 --- a/stdlib/@tests/stubtest_allowlists/py314.txt +++ b/stdlib/@tests/stubtest_allowlists/py314.txt @@ -50,8 +50,6 @@ functools.partialmethod.__new__ # >= 3.12 # ======= -zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in different Python versions - # Types that require `__setattr__` and `__delattr__` for typing purposes: types.SimpleNamespace.__setattr__ types.SimpleNamespace.__delattr__ diff --git a/stdlib/zoneinfo/__init__.pyi b/stdlib/zoneinfo/__init__.pyi index 35381758a..e9f54fbf2 100644 --- a/stdlib/zoneinfo/__init__.pyi +++ b/stdlib/zoneinfo/__init__.pyi @@ -1,3 +1,4 @@ +import sys from collections.abc import Iterable from datetime import datetime, timedelta, tzinfo from typing_extensions import Self @@ -17,8 +18,13 @@ class ZoneInfo(tzinfo): def __new__(cls, key: str) -> Self: ... @classmethod def no_cache(cls, key: str) -> Self: ... - @classmethod - def from_file(cls, fobj: _IOBytes, /, key: str | None = None) -> Self: ... + if sys.version_info >= (3, 12): + @classmethod + def from_file(cls, file_obj: _IOBytes, /, key: str | None = None) -> Self: ... + else: + @classmethod + def from_file(cls, fobj: _IOBytes, /, key: str | None = None) -> Self: ... + @classmethod def clear_cache(cls, *, only_keys: Iterable[str] | None = None) -> None: ... def tzname(self, dt: datetime | None, /) -> str | None: ...