Skip to content

Commit aec45a2

Browse files
committed
♻️ move SequenceProxy to private module
1 parent ad777e4 commit aec45a2

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

discord/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
from .ui.view import View
6565
from .user import ClientUser, User
6666
from .utils import MISSING
67+
from .utils.private import SequenceProxy
6768
from .voice_client import VoiceClient
6869
from .webhook import Webhook
6970
from .widget import Widget
@@ -385,7 +386,7 @@ def cached_messages(self) -> Sequence[Message]:
385386
386387
.. versionadded:: 1.1
387388
"""
388-
return utils.SequenceProxy(self._connection._messages or [])
389+
return SequenceProxy(self._connection._messages or [])
389390

390391
@property
391392
def private_channels(self) -> list[PrivateChannel]:

discord/utils/__init__.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
from __future__ import annotations
2727

28-
import collections.abc
2928
import json
3029
from typing import (
3130
TYPE_CHECKING,
@@ -36,7 +35,6 @@
3635
Iterator,
3736
Mapping,
3837
Protocol,
39-
Sequence,
4038
TypeVar,
4139
Union,
4240
overload,
@@ -172,34 +170,6 @@ def decorator(func: Callable[[T], T_co]) -> CachedSlotProperty[T, T_co]:
172170
return decorator
173171

174172

175-
class SequenceProxy(Generic[T_co], collections.abc.Sequence):
176-
"""Read-only proxy of a Sequence."""
177-
178-
def __init__(self, proxied: Sequence[T_co]):
179-
self.__proxied = proxied
180-
181-
def __getitem__(self, idx: int) -> T_co:
182-
return self.__proxied[idx]
183-
184-
def __len__(self) -> int:
185-
return len(self.__proxied)
186-
187-
def __contains__(self, item: Any) -> bool:
188-
return item in self.__proxied
189-
190-
def __iter__(self) -> Iterator[T_co]:
191-
return iter(self.__proxied)
192-
193-
def __reversed__(self) -> Iterator[T_co]:
194-
return reversed(self.__proxied)
195-
196-
def index(self, value: Any, *args, **kwargs) -> int:
197-
return self.__proxied.index(value, *args, **kwargs)
198-
199-
def count(self, value: Any) -> int:
200-
return self.__proxied.count(value)
201-
202-
203173
async def get_or_fetch(obj, attr: str, id: int, *, default: Any = MISSING) -> Any:
204174
"""|coro|
205175

discord/utils/private.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import array
44
import asyncio
5+
import collections.abc
56
import datetime
67
import functools
78
import re
@@ -26,8 +27,12 @@
2627
Coroutine,
2728
Awaitable,
2829
reveal_type,
30+
Generic,
31+
Sequence,
32+
Iterator,
2933
)
3034

35+
from . import T_co
3136
from ..errors import InvalidArgument, HTTPException
3237

3338
if TYPE_CHECKING:
@@ -456,3 +461,31 @@ def decorator(overridden: T) -> T:
456461
return overridden
457462

458463
return decorator
464+
465+
466+
class SequenceProxy(collections.abc.Sequence, Generic[T_co]):
467+
"""Read-only proxy of a Sequence."""
468+
469+
def __init__(self, proxied: Sequence[T_co]):
470+
self.__proxied = proxied
471+
472+
def __getitem__(self, idx: int) -> T_co:
473+
return self.__proxied[idx]
474+
475+
def __len__(self) -> int:
476+
return len(self.__proxied)
477+
478+
def __contains__(self, item: Any) -> bool:
479+
return item in self.__proxied
480+
481+
def __iter__(self) -> Iterator[T_co]:
482+
return iter(self.__proxied)
483+
484+
def __reversed__(self) -> Iterator[T_co]:
485+
return reversed(self.__proxied)
486+
487+
def index(self, value: Any, *args, **kwargs) -> int:
488+
return self.__proxied.index(value, *args, **kwargs)
489+
490+
def count(self, value: Any) -> int:
491+
return self.__proxied.count(value)

0 commit comments

Comments
 (0)