From e072a36fffbbfc68eb3e6f6e052318754d068bf9 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sun, 24 May 2026 01:13:41 -0700 Subject: [PATCH] calendar: fix iteration Fixes #15826 --- stdlib/@tests/stubtest_allowlists/common.txt | 5 ++++- stdlib/calendar.pyi | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index a3c22aa18f76..29d91719c50c 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -236,8 +236,11 @@ _?ctypes.Union.__getattr__ # doesn't exist, but makes things easy if we pretend _?ctypes.Union.__setattr__ # doesn't exist, but makes things easy if we pretend it does # Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__) -# These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220 +# These would ideally be special-cased by type checkers. +# See https://github.com/python/mypy/issues/2220 and https://github.com/python/typeshed/issues/7813 _?ctypes.Array.__iter__ +calendar._localized_day.__iter__ +calendar._localized_month.__iter__ dataclasses.KW_ONLY # white lies around defaults diff --git a/stdlib/calendar.pyi b/stdlib/calendar.pyi index 45c0c7b8346c..63ec715fb51b 100644 --- a/stdlib/calendar.pyi +++ b/stdlib/calendar.pyi @@ -2,7 +2,7 @@ import datetime import enum import sys from _typeshed import Unused -from collections.abc import Iterable +from collections.abc import Iterable, Iterator from time import struct_time from typing import ClassVar, Final, TypeAlias, overload @@ -170,6 +170,7 @@ class _localized_month: def __getitem__(self, i: slice) -> list[str]: ... def __len__(self) -> int: ... + def __iter__(self) -> Iterator[str]: ... class _localized_day: format: str @@ -181,6 +182,7 @@ class _localized_day: def __getitem__(self, i: slice) -> list[str]: ... def __len__(self) -> int: ... + def __iter__(self) -> Iterator[str]: ... day_name: _localized_day day_abbr: _localized_day