GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix annotations for `builtins.reversed.__new__` by jorenham · Pull Request #11646 · python/typeshed

Fix annotations for builtins.reversed.__new__ #11646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
srittau merged 5 commits into python:main from jorenham:re-versed
Jul 23, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Fix annotations for builtins.reversed.__new__ #11646

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
9c678d5
stricter and more tests for `builtins.reversed`
jorenham Mar 21, 2024
1137d3a
fix `builtins.reversed`
jorenham Mar 21, 2024
274f2a8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 21, 2024
d5c645a
Restore `# type: ignore[misc]` on `reversed.__new__`
jorenham Jul 22, 2026
6dd7d7f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 22, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

16 changes: 15 additions & 1 deletion 16 stdlib/@tests/test_cases/builtins/check_reversed.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ def __getitem__(self, item: int) -> _T:


len_and_get_item: MyLenAndGetItem[int] = MyLenAndGetItem()
assert_type(list(reversed(len_and_get_item)), "list[int]")
assert_type(reversed(len_and_get_item), "reversed[int]")


class UnTrue:
def __reversed__(self) -> UnFalse:
return UnFalse()


class UnFalse:
def __reversed__(self) -> UnTrue:
return UnTrue()


assert_type(reversed(UnTrue()), "UnFalse")
assert_type(reversed(reversed(UnTrue())), "UnTrue")
22 changes: 17 additions & 5 deletions 22 stdlib/builtins.pyi
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ from _typeshed import (
SupportsRichComparisonT,
SupportsWrite,
)
from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Set as AbstractSet, Sized
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
from os import PathLike
from types import CellType, CodeType, EllipsisType, GenericAlias, NotImplementedType, TracebackType, UnionType
Expand Down Expand Up @@ -281,6 +281,7 @@ class int:
*,
signed: bool = False,
) -> Self: ...

else:
def to_bytes(self, length: SupportsIndex, byteorder: Literal["little", "big"], *, signed: bool = False) -> bytes: ...
@classmethod
Expand Down Expand Up @@ -344,6 +345,7 @@ class int:
def __floor__(self) -> int: ...
if sys.version_info >= (3, 14):
def __round__(self, ndigits: SupportsIndex | None = None, /) -> int: ...

else:
def __round__(self, ndigits: SupportsIndex = ..., /) -> int: ...

Expand Down Expand Up @@ -770,6 +772,7 @@ class bytes(Sequence[int]):
def partition(self, sep: ReadableBuffer, /) -> tuple[bytes, bytes, bytes]: ...
if sys.version_info >= (3, 15):
def replace(self, old: ReadableBuffer, new: ReadableBuffer, /, count: SupportsIndex = -1) -> bytes: ...

else:
def replace(self, old: ReadableBuffer, new: ReadableBuffer, count: SupportsIndex = -1, /) -> bytes: ...

Expand Down Expand Up @@ -890,6 +893,7 @@ class bytearray(MutableSequence[int]):
def removesuffix(self, suffix: ReadableBuffer, /) -> bytearray: ...
if sys.version_info >= (3, 15):
def replace(self, old: ReadableBuffer, new: ReadableBuffer, /, count: SupportsIndex = -1) -> bytearray: ...

else:
def replace(self, old: ReadableBuffer, new: ReadableBuffer, count: SupportsIndex = -1, /) -> bytearray: ...

Expand Down Expand Up @@ -1042,6 +1046,7 @@ class memoryview(Sequence[_I]):
if sys.version_info >= (3, 14):
def index(self, value: object, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ...
def count(self, value: object, /) -> int: ...

else:
# These are inherited from the Sequence ABC, but don't actually exist on memoryview.
# See https://github.com/python/cpython/issues/125420
Expand Down Expand Up @@ -1128,6 +1133,7 @@ class slice(Generic[_StartT_co, _StopT_co, _StepT_co]):
def __eq__(self, value: object, /) -> bool: ...
if sys.version_info >= (3, 12):
def __hash__(self) -> int: ...

else:
__hash__: ClassVar[None] # type: ignore[assignment]

Expand Down Expand Up @@ -1202,6 +1208,7 @@ class function:
closure: tuple[CellType, ...] | None = None,
kwdefaults: dict[str, object] | None = None,
) -> Self: ...

else:
def __new__(
cls,
Expand Down Expand Up @@ -1359,6 +1366,7 @@ class dict(MutableMapping[_KT, _VT]):
def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
@overload
def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ...

else:
def __or__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
Expand Down Expand Up @@ -2145,15 +2153,19 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex

quit: _sitebuiltins.Quitter

@type_check_only
class _SupportsReversed(Protocol[_T_co]):
def __reversed__(self) -> _T_co: ...

@disjoint_base
class reversed(Generic[_T]):
class reversed(Generic[_T_co]):
@overload
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
def __new__(cls, sequence: _SupportsReversed[_T], /) -> _T: ... # type: ignore[misc]
@overload
def __new__(cls, sequence: SupportsLenAndGetItem[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
def __new__(cls, sequence: SupportsLenAndGetItem[_T_co], /) -> Self: ...

def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
def __next__(self) -> _T_co: ...
def __length_hint__(self) -> int: ...

def repr(obj: object, /) -> str: ...
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.