mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
Added SQLAlchemy annotations (#1029)
* Added SQLAlchemy annotations * Made Connection and Engine sublcasses of Connectable (python/typeshed#1018) * Moved execute() from Connection to Connectable * Made RowProxy a Mapping and removed Mapping inherited methods * Made ResultProxy an Iterator of RowProxy * Added most relevant methods for fetching of ResultProxy * Added where(), group_by(), order_by() and limit() to Select * Follow squalchemy module structure * Created sqlalchemy.engine.result and moved ResultProxy and RowProxy there * Created sqlalchemy.engine.interfaces and moved Connectable there * Added non-deprecated methods to Connectable: connect, contextual_connect and scalar * Fixed return type of scalar() to Any * Missed ResultProxy scalar return ... had it in Connectable only.
This commit is contained in:
committed by
Jelle Zijlstra
parent
433b1b2ebc
commit
5b47bc956e
@@ -4,8 +4,8 @@
|
||||
|
||||
from .base import Connection as Connection
|
||||
from .base import Engine as Engine
|
||||
from .base import RowProxy as RowProxy
|
||||
from .base import Transaction as Transaction
|
||||
from .result import RowProxy as RowProxy
|
||||
|
||||
def create_engine(*args, **kwargs): ...
|
||||
def engine_from_config(configuration, prefix=..., **kwargs): ...
|
||||
|
||||
17
third_party/2and3/sqlalchemy/engine/base.pyi
vendored
17
third_party/2and3/sqlalchemy/engine/base.pyi
vendored
@@ -1,20 +1,9 @@
|
||||
from typing import Any, List, Tuple
|
||||
from .interfaces import Connectable
|
||||
|
||||
# Dummy until I figure out something better.
|
||||
class Connectable:
|
||||
pass
|
||||
|
||||
class Connection:
|
||||
class Connection(Connectable):
|
||||
def begin(self): ...
|
||||
def execute(self, object, *multiparams, **params): ...
|
||||
|
||||
class Engine(object): ...
|
||||
|
||||
class RowProxy:
|
||||
def items(self) -> List[Tuple[Any, Any]]: ...
|
||||
def keys(self) -> List[Any]: ...
|
||||
def values(self) -> List[Any]: ...
|
||||
def __getitem__(self, key: str): ...
|
||||
class Engine(Connectable): ...
|
||||
|
||||
class Transaction:
|
||||
def commit(self): ...
|
||||
|
||||
13
third_party/2and3/sqlalchemy/engine/interfaces.pyi
vendored
Normal file
13
third_party/2and3/sqlalchemy/engine/interfaces.pyi
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
from typing import Any, TYPE_CHECKING
|
||||
from .result import ResultProxy
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .base import Connection
|
||||
|
||||
class Connectable:
|
||||
def execute(self, object, *multiparams: Any, **params: Any) -> ResultProxy: ...
|
||||
def connect(self, **kwargs: Any) -> Connection: ...
|
||||
def contextual_connect(self) -> Connection: ...
|
||||
# Note: The return type `Any` should be a DB API 2 value type once defined
|
||||
# TODO: See #1037
|
||||
def scalar(self, object, *multiparams: Any, **params: Any) -> Any: ...
|
||||
22
third_party/2and3/sqlalchemy/engine/result.pyi
vendored
Normal file
22
third_party/2and3/sqlalchemy/engine/result.pyi
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
from typing import Any, Iterator, List, Mapping, Optional
|
||||
|
||||
# Note: The value type `Any` should be a DB API 2 value type once defined
|
||||
# TODO: See #1037
|
||||
|
||||
class RowProxy(Mapping[str, Any]): ...
|
||||
|
||||
class ResultProxy(Iterator[RowProxy]):
|
||||
def keys(self) -> List[str]: ...
|
||||
def close(self) -> None: ...
|
||||
def __iter__(self) -> Iterator[RowProxy]: ...
|
||||
def fetchall(self) -> Iterator[RowProxy]: ...
|
||||
def fetchmany(self, size: Optional[int]=None) -> Iterator[RowProxy]: ...
|
||||
def fetchone(self) -> Optional[RowProxy]: ...
|
||||
def first(self) -> Optional[RowProxy]: ...
|
||||
|
||||
# Note: The return type `Any` should be a DB API 2 value type once defined
|
||||
# TODO: See #1037
|
||||
def scalar(self) -> Any: ...
|
||||
|
||||
@property
|
||||
def rowcount(self) -> int: ...
|
||||
@@ -69,7 +69,13 @@ class ForUpdateArg(ClauseElement): ...
|
||||
class SelectBase(Executable, FromClause): ...
|
||||
class GenerativeSelect(SelectBase): ...
|
||||
class CompoundSelect(GenerativeSelect): ...
|
||||
class Select(HasPrefixes, HasSuffixes, GenerativeSelect): ...
|
||||
|
||||
class Select(HasPrefixes, HasSuffixes, GenerativeSelect):
|
||||
def where(self, whereclause) -> Select: ...
|
||||
def group_by(self, *clauses) -> Select: ...
|
||||
def order_by(self, *clauses) -> Select: ...
|
||||
def limit(self, limit: int) -> Select: ...
|
||||
|
||||
class ScalarSelect(Generative, Grouping): ...
|
||||
class Exists(UnaryExpression): ...
|
||||
class TextAsFrom(SelectBase): ...
|
||||
|
||||
Reference in New Issue
Block a user