Skip to content

Commit e08939a

Browse files
author
Mark Edwards
committed
Implement SizedSliceable protocol in src/graphql_relay/connection/arrayconnection.py
1 parent 4865837 commit e08939a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Diff for: src/graphql_relay/connection/arrayconnection.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import binascii
22
import warnings
3-
from typing import Any, Optional, Sequence
3+
from typing import Any, Iterator, Optional, Sequence
4+
try:
5+
from typing import Protocol
6+
except ImportError:
7+
from typing_extensions import Protocol # type: ignore
48

59
from ..utils.base64 import base64, unbase64
610
from .connectiontypes import (
@@ -25,8 +29,14 @@
2529
]
2630

2731

32+
class SizedSliceable(Protocol):
33+
def __getitem__(self, index: slice) -> Any: ...
34+
def __iter__(self) -> Iterator: ...
35+
def __len__(self) -> int: ...
36+
37+
2838
def connection_from_array(
29-
data: Sequence,
39+
data: SizedSliceable,
3040
args: ConnectionArguments = None,
3141
connection_type: ConnectionConstructor = Connection,
3242
edge_type: EdgeConstructor = Edge,
@@ -83,7 +93,7 @@ def connection_from_list(
8393

8494

8595
def connection_from_array_slice(
86-
array_slice: Sequence,
96+
array_slice: SizedSliceable,
8797
args: ConnectionArguments = None,
8898
slice_start: int = 0,
8999
array_length: int = None,

0 commit comments

Comments
 (0)