Skip to content

Commit dac0f2c

Browse files
authored
Fix typing for ColumnCollection and subclasses (#65)
1 parent b09f072 commit dac0f2c

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

sqlalchemy-stubs/sql/base.pyi

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ from typing import TypeVar
1616
from typing import Union
1717

1818
from . import roles
19-
from .schema import Column
19+
from .elements import ColumnElement
2020
from .traversals import HasCacheKey
2121
from .traversals import HasCopyInternals
2222
from .visitors import ClauseVisitor
@@ -30,8 +30,8 @@ _T = TypeVar("_T")
3030
_SC = TypeVar("_SC", bound=SingletonConstant)
3131
_O = TypeVar("_O", bound=Options)
3232
_E = TypeVar("_E", bound=Executable)
33-
_C = TypeVar("_C", bound=Column[Any])
34-
_OC = TypeVar("_OC", bound=Column[Any])
33+
_CE = TypeVar("_CE", bound=ColumnElement[Any])
34+
_OCE = TypeVar("_OCE", bound=ColumnElement[Any])
3535

3636
coercions: ModuleType
3737
elements: ModuleType
@@ -145,56 +145,58 @@ class SchemaEventTarget: ...
145145
class SchemaVisitor(ClauseVisitor):
146146
__traverse_options__: Any = ...
147147

148-
class ColumnCollection(Generic[_C]):
148+
class ColumnCollection(Generic[_CE]):
149149
def __init__(
150-
self, columns: Optional[Iterable[Tuple[str, _C]]] = ...
150+
self, columns: Optional[Iterable[Tuple[str, _CE]]] = ...
151151
) -> None: ...
152-
def keys(self) -> List[_C]: ...
152+
def keys(self) -> List[_CE]: ...
153153
def values(self) -> List[str]: ...
154-
def items(self) -> List[Tuple[str, _C]]: ...
154+
def items(self) -> List[Tuple[str, _CE]]: ...
155155
def __bool__(self) -> bool: ...
156156
def __len__(self) -> int: ...
157-
def __iter__(self) -> Iterator[_C]: ...
158-
def __getitem__(self, key: str) -> _C: ...
159-
def __getattr__(self, key: str) -> _C: ...
157+
def __iter__(self) -> Iterator[_CE]: ...
158+
def __getitem__(self, key: str) -> _CE: ...
159+
def __getattr__(self, key: str) -> _CE: ...
160160
def __contains__(self, key: str) -> bool: ...
161161
def compare(self, other: Any) -> bool: ...
162162
def __eq__(self, other: Any) -> bool: ...
163163
@overload
164-
def get(self, key: str) -> Optional[_C]: ...
164+
def get(self, key: str) -> Optional[_CE]: ...
165165
@overload
166-
def get(self, key: str, default: _T) -> Union[_C, _T]: ...
167-
def __setitem__(self, key: str, value: _C) -> None: ...
166+
def get(self, key: str, default: _T) -> Union[_CE, _T]: ...
167+
def __setitem__(self, key: str, value: _CE) -> None: ...
168168
def __delitem__(self, key: str) -> None: ...
169-
def __setattr__(self, key: str, obj: _C) -> None: ...
169+
def __setattr__(self, key: str, obj: _CE) -> None: ...
170170
def clear(self) -> None: ...
171-
def remove(self, column: _C) -> None: ...
171+
def remove(self, column: _CE) -> None: ...
172172
def update(
173-
self, iter_: Union[Mapping[str, _C], Iterable[Tuple[str, _C]]]
173+
self, iter_: Union[Mapping[str, _CE], Iterable[Tuple[str, _CE]]]
174174
) -> None: ...
175175
__hash__: Any = ...
176-
def add(self, column: _C, key: Optional[str] = ...) -> None: ...
177-
def contains_column(self, col: Column[Any]) -> bool: ...
178-
def as_immutable(self) -> ImmutableColumnCollection[_C]: ...
176+
def add(self, column: _CE, key: Optional[str] = ...) -> None: ...
177+
def contains_column(self, col: ColumnElement[Any]) -> bool: ...
178+
def as_immutable(self) -> ImmutableColumnCollection[_CE]: ...
179179
def corresponding_column(
180-
self, column: Column[Any], require_embedded: bool = ...
181-
) -> Optional[_C]: ...
182-
183-
class DedupeColumnCollection(ColumnCollection[_C]):
184-
def add(self, column: _C, key: Optional[str] = ...) -> None: ...
185-
def extend(self, iter_: Iterable[_C]) -> None: ...
186-
def remove(self, column: _C) -> None: ...
187-
def replace(self, column: _C) -> None: ...
188-
189-
class ImmutableColumnCollection(util.ImmutableContainer, ColumnCollection[_C]):
190-
def __init__(self, collection: ColumnCollection[_C]) -> None: ...
191-
def add(self, column: _C, key: Optional[str] = ...) -> NoReturn: ...
192-
def extend(self, iter_: Iterable[_C]) -> NoReturn: ...
193-
def remove(self, column: _C) -> NoReturn: ...
194-
195-
class ColumnSet(util.ordered_column_set[_C]):
196-
def contains_column(self, col: Column[Any]) -> bool: ...
197-
def extend(self, cols: Iterable[_C]) -> None: ...
198-
def __add__(self, other: Iterable[_OC]) -> List[Union[_C, _OC]]: ... # type: ignore[override]
180+
self, column: ColumnElement[Any], require_embedded: bool = ...
181+
) -> Optional[_CE]: ...
182+
183+
class DedupeColumnCollection(ColumnCollection[_CE]):
184+
def add(self, column: _CE, key: Optional[str] = ...) -> None: ...
185+
def extend(self, iter_: Iterable[_CE]) -> None: ...
186+
def remove(self, column: _CE) -> None: ...
187+
def replace(self, column: _CE) -> None: ...
188+
189+
class ImmutableColumnCollection(
190+
util.ImmutableContainer, ColumnCollection[_CE]
191+
):
192+
def __init__(self, collection: ColumnCollection[_CE]) -> None: ...
193+
def add(self, column: _CE, key: Optional[str] = ...) -> NoReturn: ...
194+
def extend(self, iter_: Iterable[_CE]) -> NoReturn: ...
195+
def remove(self, column: _CE) -> NoReturn: ...
196+
197+
class ColumnSet(util.ordered_column_set[_CE]):
198+
def contains_column(self, col: ColumnElement[Any]) -> bool: ...
199+
def extend(self, cols: Iterable[_CE]) -> None: ...
200+
def __add__(self, other: Iterable[_OCE]) -> List[Union[_CE, _OCE]]: ... # type: ignore[override]
199201
def __eq__(self, other: Any) -> Any: ...
200202
def __hash__(self) -> int: ... # type: ignore[override]

0 commit comments

Comments
 (0)