Skip to content

Commit 59ed14f

Browse files
authored
Improve engine.row (#99)
1 parent b64325e commit 59ed14f

File tree

1 file changed

+63
-51
lines changed

1 file changed

+63
-51
lines changed

sqlalchemy-stubs/engine/row.pyi

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
# fmt: off
2-
import abc
31
from typing import Any
2+
from typing import Collection
3+
from typing import Generic
4+
from typing import ItemsView
5+
from typing import Iterator
6+
from typing import KeysView
7+
from typing import List
8+
from typing import Mapping
9+
from typing import Sequence
10+
from typing import Tuple
11+
from typing import Type
12+
from typing import TypeVar
13+
from typing import ValuesView
414

5-
from sqlalchemy.cresultproxy import BaseRow as BaseRow
6-
from sqlalchemy.cresultproxy import safe_rowproxy_reconstructor as safe_rowproxy_reconstructor
7-
from .. import util as util
8-
from ..util.compat import collections_abc as collections_abc
9-
# fmt: on
15+
from .result import ResultMetaData
16+
from .result import RMKeyView
17+
18+
_T = TypeVar("_T")
1019

1120
MD_INDEX: int
1221

13-
def rowproxy_reconstructor(cls, state: Any): ...
22+
def rowproxy_reconstructor(cls: Type[_T], state: Any) -> _T: ...
1423

1524
KEY_INTEGER_ONLY: int
1625
KEY_OBJECTS_ONLY: int
@@ -20,59 +29,62 @@ KEY_OBJECTS_NO_WARN: int
2029
class BaseRow:
2130
def __init__(
2231
self,
23-
parent: Any,
32+
parent: ResultMetaData,
2433
processors: Any,
2534
keymap: Any,
2635
key_style: Any,
2736
data: Any,
2837
) -> None: ...
29-
def __reduce__(self): ...
30-
def __iter__(self) -> Any: ...
31-
def __len__(self): ...
32-
def __hash__(self) -> Any: ...
33-
def __getitem__(self, key: Any): ...
34-
def __getattr__(self, name: Any): ...
38+
def __reduce__(self) -> Any: ...
39+
def __iter__(self) -> Iterator[Any]: ...
40+
def __len__(self) -> int: ...
41+
def __hash__(self) -> int: ...
42+
def __getitem__(self, key: Any) -> Any: ...
43+
def __getattr__(self, name: Any) -> Any: ...
3544

36-
class Row(BaseRow, collections_abc.Sequence, metaclass=abc.ABCMeta):
37-
def __contains__(self, key: Any): ...
38-
__hash__: Any = ...
39-
def __lt__(self, other: Any) -> Any: ...
40-
def __le__(self, other: Any) -> Any: ...
41-
def __ge__(self, other: Any) -> Any: ...
42-
def __gt__(self, other: Any) -> Any: ...
43-
def __eq__(self, other: Any) -> Any: ...
44-
def __ne__(self, other: Any) -> Any: ...
45-
def keys(self): ...
45+
class Row(BaseRow, Sequence[Any]):
46+
@property
47+
def _mapping(self) -> RowMapping: ...
48+
def __contains__(self, key: Any) -> bool: ...
49+
def __hash__(self) -> int: ...
50+
def __lt__(self, other: Any) -> bool: ...
51+
def __le__(self, other: Any) -> bool: ...
52+
def __ge__(self, other: Any) -> bool: ...
53+
def __gt__(self, other: Any) -> bool: ...
54+
def __eq__(self, other: Any) -> bool: ...
55+
def __ne__(self, other: Any) -> bool: ...
56+
def keys(self) -> List[str]: ...
4657

47-
class LegacyRow(Row, metaclass=abc.ABCMeta):
48-
def __contains__(self, key: Any): ...
49-
__getitem__: Any = ...
50-
def has_key(self, key: Any): ...
51-
def items(self): ...
52-
def iterkeys(self): ...
53-
def itervalues(self): ...
54-
def values(self): ...
58+
class LegacyRow(Row):
59+
def __contains__(self, key: Any) -> bool: ...
60+
def __getitem__(self, key: Any) -> Any: ...
61+
def has_key(self, key: str) -> bool: ...
62+
def items(self) -> List[Tuple[str, Any]]: ...
63+
def iterkeys(self) -> Iterator[str]: ...
64+
def itervalues(self) -> Iterator[Any]: ...
65+
def values(self) -> List[Any]: ...
5566

5667
BaseRowProxy = BaseRow
5768
RowProxy = Row
5869

59-
class ROMappingView(
60-
collections_abc.KeysView,
61-
collections_abc.ValuesView,
62-
collections_abc.ItemsView,
70+
class ROMappingView( # type: ignore[misc]
71+
KeysView[str],
72+
ValuesView[Any],
73+
ItemsView[str, Any],
74+
Generic[_T],
6375
):
64-
def __init__(self, mapping: Any, items: Any) -> None: ...
65-
def __len__(self): ...
66-
def __iter__(self) -> Any: ...
67-
def __contains__(self, item: Any): ...
68-
def __eq__(self, other: Any) -> Any: ...
69-
def __ne__(self, other: Any) -> Any: ...
76+
def __init__(self, mapping: RowMapping, items: Collection[_T]) -> None: ...
77+
def __len__(self) -> int: ...
78+
def __iter__(self) -> Iterator[Tuple[str, _T]]: ... # type: ignore[override]
79+
def __contains__(self, item: Any) -> bool: ...
80+
def __eq__(self, other: Any) -> bool: ...
81+
def __ne__(self, other: Any) -> bool: ...
7082

71-
class RowMapping(BaseRow, collections_abc.Mapping):
72-
__getitem__: Any = ...
73-
def __iter__(self) -> Any: ...
74-
def __len__(self): ...
75-
def __contains__(self, key: Any): ...
76-
def items(self): ...
77-
def keys(self): ...
78-
def values(self): ...
83+
class RowMapping(BaseRow, Mapping[str, Any]):
84+
def __getitem__(self, key: str) -> Any: ...
85+
def __iter__(self) -> Iterator[str]: ...
86+
def __len__(self) -> int: ...
87+
def __contains__(self, key: Any) -> bool: ...
88+
def items(self) -> ROMappingView[Tuple[str, Any]]: ... # type: ignore[override]
89+
def keys(self) -> RMKeyView: ...
90+
def values(self) -> ROMappingView[Any]: ...

0 commit comments

Comments
 (0)