Skip to content

Commit

Permalink
Merge pull request #2 from peterlandry/main
Browse files Browse the repository at this point in the history
Fix most linting errors
  • Loading branch information
farahats9 authored Jul 27, 2023
2 parents 4ce8d07 + eff0803 commit c5bdbcc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 57 deletions.
46 changes: 3 additions & 43 deletions sqlmodel/engine/result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Generic, Iterator, List, Optional, Sequence, TypeVar
from typing import Generic, Iterator, Optional, Sequence, Tuple, TypeVar

from sqlalchemy.engine.result import Result as _Result
from sqlalchemy.engine.result import ScalarResult as _ScalarResult
Expand Down Expand Up @@ -35,45 +35,5 @@ def one(self) -> _T:
return super().one()


class Result(_Result[_T], Generic[_T]):
def scalars(self, index: int = 0) -> ScalarResult[_T]:
return super().scalars(index) # type: ignore

def __iter__(self) -> Iterator[_T]: # type: ignore
return super().__iter__() # type: ignore

def __next__(self) -> _T: # type: ignore
return super().__next__() # type: ignore

def partitions(self, size: Optional[int] = None) -> Iterator[List[_T]]: # type: ignore
return super().partitions(size) # type: ignore

def fetchall(self) -> List[_T]: # type: ignore
return super().fetchall() # type: ignore

def fetchone(self) -> Optional[_T]: # type: ignore
return super().fetchone() # type: ignore

def fetchmany(self, size: Optional[int] = None) -> List[_T]: # type: ignore
return super().fetchmany() # type: ignore

def all(self) -> List[_T]: # type: ignore
return super().all() # type: ignore

def first(self) -> Optional[_T]: # type: ignore
return super().first() # type: ignore

def one_or_none(self) -> Optional[_T]: # type: ignore
return super().one_or_none() # type: ignore

def scalar_one(self) -> _T:
return super().scalar_one() # type: ignore

def scalar_one_or_none(self) -> Optional[_T]:
return super().scalar_one_or_none()

def one(self) -> _T: # type: ignore
return super().one() # type: ignore

def scalar(self) -> Optional[_T]:
return super().scalar() # type: ignore
class Result(_Result[Tuple[_T]], Generic[_T]):
...
3 changes: 2 additions & 1 deletion sqlmodel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Callable,
ClassVar,
Dict,
ForwardRef,
List,
Mapping,
Optional,
Expand All @@ -29,7 +30,7 @@
from pydantic.fields import FieldInfo as PydanticFieldInfo
from pydantic.fields import ModelField, Undefined, UndefinedType
from pydantic.main import ModelMetaclass, validate_model
from pydantic.typing import ForwardRef, NoArgAnyCallable, resolve_annotations
from pydantic.typing import NoArgAnyCallable, resolve_annotations
from pydantic.utils import ROOT_KEY, Representation
from sqlalchemy import Boolean, Column, Date, DateTime
from sqlalchemy import Enum as sa_Enum
Expand Down
32 changes: 23 additions & 9 deletions sqlmodel/orm/session.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
from typing import Any, Mapping, Optional, Sequence, Type, TypeVar, Union, overload
from typing import (
Any,
Dict,
Mapping,
Optional,
Sequence,
Type,
TypeVar,
Union,
overload,
)

from sqlalchemy import util
from sqlalchemy.orm import Mapper as _Mapper
from sqlalchemy.orm import Query as _Query
from sqlalchemy.orm import Session as _Session
from sqlalchemy.sql.base import Executable as _Executable
from sqlalchemy.sql.selectable import ForUpdateArg as _ForUpdateArg
from sqlmodel.sql.expression import Select, SelectOfScalar
from typing_extensions import Literal

Expand All @@ -21,7 +33,7 @@ def exec(
*,
params: Optional[Union[Mapping[str, Any], Sequence[Mapping[str, Any]]]] = None,
execution_options: Mapping[str, Any] = util.EMPTY_DICT,
bind_arguments: Optional[Mapping[str, Any]] = None,
bind_arguments: Optional[Dict[str, Any]] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
**kw: Any,
Expand All @@ -35,7 +47,7 @@ def exec(
*,
params: Optional[Union[Mapping[str, Any], Sequence[Mapping[str, Any]]]] = None,
execution_options: Mapping[str, Any] = util.EMPTY_DICT,
bind_arguments: Optional[Mapping[str, Any]] = None,
bind_arguments: Optional[Dict[str, Any]] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
**kw: Any,
Expand All @@ -52,7 +64,7 @@ def exec(
*,
params: Optional[Union[Mapping[str, Any], Sequence[Mapping[str, Any]]]] = None,
execution_options: Mapping[str, Any] = util.EMPTY_DICT,
bind_arguments: Optional[Mapping[str, Any]] = None,
bind_arguments: Optional[Dict[str, Any]] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
**kw: Any,
Expand All @@ -74,8 +86,8 @@ def execute(
self,
statement: _Executable,
params: Optional[Union[Mapping[str, Any], Sequence[Mapping[str, Any]]]] = None,
execution_options: Optional[Mapping[str, Any]] = util.EMPTY_DICT,
bind_arguments: Optional[Mapping[str, Any]] = None,
execution_options: Mapping[str, Any] = util.EMPTY_DICT,
bind_arguments: Optional[Dict[str, Any]] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
**kw: Any,
Expand Down Expand Up @@ -122,13 +134,14 @@ def query(self, *entities: Any, **kwargs: Any) -> "_Query[Any]":

def get(
self,
entity: Type[_TSelectParam],
entity: Union[Type[_TSelectParam], "_Mapper[_TSelectParam]"],
ident: Any,
options: Optional[Sequence[Any]] = None,
populate_existing: bool = False,
with_for_update: Optional[Union[Literal[True], Mapping[str, Any]]] = None,
with_for_update: Optional[_ForUpdateArg] = None,
identity_token: Optional[Any] = None,
execution_options: Optional[Mapping[Any, Any]] = util.EMPTY_DICT,
execution_options: Mapping[Any, Any] = util.EMPTY_DICT,
bind_arguments: Optional[Dict[str, Any]] = None,
) -> Optional[_TSelectParam]:
return super().get(
entity,
Expand All @@ -138,4 +151,5 @@ def get(
with_for_update=with_for_update,
identity_token=identity_token,
execution_options=execution_options,
bind_arguments=bind_arguments
)
4 changes: 2 additions & 2 deletions sqlmodel/sql/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
_TSelect = TypeVar("_TSelect")


class Select(_Select[_TSelect], Generic[_TSelect]):
class Select(_Select[Tuple[_TSelect]], Generic[_TSelect]):
inherit_cache = True


# This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different
# purpose. This is the same as a normal SQLAlchemy Select class where there's only one
# entity, so the result will be converted to a scalar by default. This way writing
# for loops on the results will feel natural.
class SelectOfScalar(_Select[_TSelect], Generic[_TSelect]):
class SelectOfScalar(_Select[Tuple[_TSelect]], Generic[_TSelect]):
inherit_cache = True


Expand Down
4 changes: 2 additions & 2 deletions sqlmodel/sql/expression.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ from sqlalchemy.sql.expression import Select as _Select

_TSelect = TypeVar("_TSelect")

class Select(_Select[_TSelect], Generic[_TSelect]):
class Select(_Select[Tuple[_TSelect]], Generic[_TSelect]):
inherit_cache = True

# This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different
# purpose. This is the same as a normal SQLAlchemy Select class where there's only one
# entity, so the result will be converted to a scalar by default. This way writing
# for loops on the results will feel natural.
class SelectOfScalar(_Select[_TSelect], Generic[_TSelect]):
class SelectOfScalar(_Select[Tuple[_TSelect]], Generic[_TSelect]):
inherit_cache = True


Expand Down

0 comments on commit c5bdbcc

Please sign in to comment.