From b9cf12918882a7fc96f62b1c9180d36b905a1baf Mon Sep 17 00:00:00 2001 From: Mohamed Farahat Date: Fri, 24 Mar 2023 14:56:26 +0200 Subject: [PATCH] fix some linting errors --- sqlmodel/engine/create.py | 2 +- sqlmodel/engine/result.py | 20 +++++++++---------- sqlmodel/main.py | 4 ++-- sqlmodel/orm/session.py | 2 +- sqlmodel/sql/expression.py | 2 +- sqlmodel/sql/sqltypes.py | 6 +++--- .../test_multiple_models/test_tutorial001.py | 14 +++++++++++-- .../test_multiple_models/test_tutorial002.py | 14 +++++++++++-- .../test_indexes/test_tutorial001.py | 14 +++++++++++-- .../test_indexes/test_tutorial006.py | 14 +++++++++++-- 10 files changed, 66 insertions(+), 26 deletions(-) diff --git a/sqlmodel/engine/create.py b/sqlmodel/engine/create.py index b2d567b..9748125 100644 --- a/sqlmodel/engine/create.py +++ b/sqlmodel/engine/create.py @@ -136,4 +136,4 @@ def create_engine( if not isinstance(query_cache_size, _DefaultPlaceholder): current_kwargs["query_cache_size"] = query_cache_size current_kwargs.update(kwargs) - return _create_engine(url, **current_kwargs) # type: ignore + return _create_engine(url, **current_kwargs) diff --git a/sqlmodel/engine/result.py b/sqlmodel/engine/result.py index 7a25422..17020d9 100644 --- a/sqlmodel/engine/result.py +++ b/sqlmodel/engine/result.py @@ -1,4 +1,4 @@ -from typing import Generic, Iterator, List, Optional, TypeVar +from typing import Generic, Iterator, List, Optional, Sequence, TypeVar from sqlalchemy.engine.result import Result as _Result from sqlalchemy.engine.result import ScalarResult as _ScalarResult @@ -6,24 +6,24 @@ from sqlalchemy.engine.result import ScalarResult as _ScalarResult _T = TypeVar("_T") -class ScalarResult(_ScalarResult, Generic[_T]): - def all(self) -> List[_T]: +class ScalarResult(_ScalarResult[_T], Generic[_T]): + def all(self) -> Sequence[_T]: return super().all() - def partitions(self, size: Optional[int] = None) -> Iterator[List[_T]]: + def partitions(self, size: Optional[int] = None) -> Iterator[Sequence[_T]]: return super().partitions(size) - def fetchall(self) -> List[_T]: + def fetchall(self) -> Sequence[_T]: return super().fetchall() - def fetchmany(self, size: Optional[int] = None) -> List[_T]: + def fetchmany(self, size: Optional[int] = None) -> Sequence[_T]: return super().fetchmany(size) def __iter__(self) -> Iterator[_T]: return super().__iter__() def __next__(self) -> _T: - return super().__next__() # type: ignore + return super().__next__() def first(self) -> Optional[_T]: return super().first() @@ -32,10 +32,10 @@ class ScalarResult(_ScalarResult, Generic[_T]): return super().one_or_none() def one(self) -> _T: - return super().one() # type: ignore + return super().one() -class Result(_Result, Generic[_T]): +class Result(_Result[_T], Generic[_T]): def scalars(self, index: int = 0) -> ScalarResult[_T]: return super().scalars(index) # type: ignore @@ -76,4 +76,4 @@ class Result(_Result, Generic[_T]): return super().one() # type: ignore def scalar(self) -> Optional[_T]: - return super().scalar() + return super().scalar() # type: ignore diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 110f023..d05fdcc 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -479,7 +479,7 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry __sqlmodel_relationships__: ClassVar[Dict[str, RelationshipProperty]] # type: ignore __name__: ClassVar[str] metadata: ClassVar[MetaData] - __allow_unmapped__ = True # https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#migration-20-step-six + __allow_unmapped__ = True # https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#migration-20-step-six class Config: orm_mode = True @@ -523,7 +523,7 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry return else: # Set in SQLAlchemy, before Pydantic to trigger events and updates - if getattr(self.__config__, "table", False) and is_instrumented(self, name): + if getattr(self.__config__, "table", False) and is_instrumented(self, name): # type: ignore set_attribute(self, name, value) # Set in Pydantic model to trigger possible validation changes, only for # non relationship values diff --git a/sqlmodel/orm/session.py b/sqlmodel/orm/session.py index 1692fdc..64f6ad7 100644 --- a/sqlmodel/orm/session.py +++ b/sqlmodel/orm/session.py @@ -118,7 +118,7 @@ class Session(_Session): Or otherwise you might want to use `session.execute()` instead of `session.query()`. """ - return super().query(*entities, **kwargs) + return super().query(*entities, **kwargs) # type: ignore def get( self, diff --git a/sqlmodel/sql/expression.py b/sqlmodel/sql/expression.py index 29e7524..f473ba4 100644 --- a/sqlmodel/sql/expression.py +++ b/sqlmodel/sql/expression.py @@ -406,4 +406,4 @@ def select(*entities: Any) -> Union[Select, SelectOfScalar]: # type: ignore def col(column_expression: Any) -> ColumnClause: # type: ignore if not isinstance(column_expression, (ColumnClause, Column, InstrumentedAttribute)): raise RuntimeError(f"Not a SQLAlchemy column: {column_expression}") - return column_expression + return column_expression # type: ignore diff --git a/sqlmodel/sql/sqltypes.py b/sqlmodel/sql/sqltypes.py index 09b8239..da6551b 100644 --- a/sqlmodel/sql/sqltypes.py +++ b/sqlmodel/sql/sqltypes.py @@ -16,7 +16,7 @@ class AutoString(types.TypeDecorator): # type: ignore def load_dialect_impl(self, dialect: Dialect) -> "types.TypeEngine[Any]": impl = cast(types.String, self.impl) if impl.length is None and dialect.name == "mysql": - return dialect.type_descriptor(types.String(self.mysql_default_length)) # type: ignore + return dialect.type_descriptor(types.String(self.mysql_default_length)) return super().load_dialect_impl(dialect) @@ -35,9 +35,9 @@ class GUID(types.TypeDecorator): # type: ignore def load_dialect_impl(self, dialect: Dialect) -> TypeEngine: # type: ignore if dialect.name == "postgresql": - return dialect.type_descriptor(UUID()) # type: ignore + return dialect.type_descriptor(UUID()) else: - return dialect.type_descriptor(CHAR(32)) # type: ignore + return dialect.type_descriptor(CHAR(32)) def process_bind_param(self, value: Any, dialect: Dialect) -> Optional[str]: if value is None: diff --git a/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py index 2fbc832..d05c4a2 100644 --- a/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py @@ -173,8 +173,18 @@ def test_tutorial(clear_sqlmodel): insp: Inspector = inspect(mod.engine) indexes = insp.get_indexes(str(mod.Hero.__tablename__)) expected_indexes = [ - {"name": "ix_hero_name", "column_names": ["name"], "unique": 0, 'dialect_options': {}}, - {"name": "ix_hero_age", "column_names": ["age"], "unique": 0, 'dialect_options': {}}, + { + "name": "ix_hero_name", + "column_names": ["name"], + "unique": 0, + "dialect_options": {}, + }, + { + "name": "ix_hero_age", + "column_names": ["age"], + "unique": 0, + "dialect_options": {}, + }, ] for index in expected_indexes: assert index in indexes, "This expected index should be in the indexes in DB" diff --git a/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py b/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py index a70e546..a8b5b7b 100644 --- a/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py +++ b/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py @@ -173,8 +173,18 @@ def test_tutorial(clear_sqlmodel): insp: Inspector = inspect(mod.engine) indexes = insp.get_indexes(str(mod.Hero.__tablename__)) expected_indexes = [ - {"name": "ix_hero_age", "column_names": ["age"], "unique": 0, 'dialect_options': {}}, - {"name": "ix_hero_name", "column_names": ["name"], "unique": 0, 'dialect_options': {}}, + { + "name": "ix_hero_age", + "column_names": ["age"], + "unique": 0, + "dialect_options": {}, + }, + { + "name": "ix_hero_name", + "column_names": ["name"], + "unique": 0, + "dialect_options": {}, + }, ] for index in expected_indexes: assert index in indexes, "This expected index should be in the indexes in DB" diff --git a/tests/test_tutorial/test_indexes/test_tutorial001.py b/tests/test_tutorial/test_indexes/test_tutorial001.py index 2394c48..bc89522 100644 --- a/tests/test_tutorial/test_indexes/test_tutorial001.py +++ b/tests/test_tutorial/test_indexes/test_tutorial001.py @@ -25,8 +25,18 @@ def test_tutorial(clear_sqlmodel): insp: Inspector = inspect(mod.engine) indexes = insp.get_indexes(str(mod.Hero.__tablename__)) expected_indexes = [ - {"name": "ix_hero_name", "column_names": ["name"], "unique": 0, 'dialect_options': {}}, - {"name": "ix_hero_age", "column_names": ["age"], "unique": 0, 'dialect_options': {}}, + { + "name": "ix_hero_name", + "column_names": ["name"], + "unique": 0, + "dialect_options": {}, + }, + { + "name": "ix_hero_age", + "column_names": ["age"], + "unique": 0, + "dialect_options": {}, + }, ] for index in expected_indexes: assert index in indexes, "This expected index should be in the indexes in DB" diff --git a/tests/test_tutorial/test_indexes/test_tutorial006.py b/tests/test_tutorial/test_indexes/test_tutorial006.py index 8283d44..8d574dd 100644 --- a/tests/test_tutorial/test_indexes/test_tutorial006.py +++ b/tests/test_tutorial/test_indexes/test_tutorial006.py @@ -26,8 +26,18 @@ def test_tutorial(clear_sqlmodel): insp: Inspector = inspect(mod.engine) indexes = insp.get_indexes(str(mod.Hero.__tablename__)) expected_indexes = [ - {"name": "ix_hero_name", "column_names": ["name"], "unique": 0, 'dialect_options': {}}, - {"name": "ix_hero_age", "column_names": ["age"], "unique": 0, 'dialect_options': {}}, + { + "name": "ix_hero_name", + "column_names": ["name"], + "unique": 0, + "dialect_options": {}, + }, + { + "name": "ix_hero_age", + "column_names": ["age"], + "unique": 0, + "dialect_options": {}, + }, ] for index in expected_indexes: assert index in indexes, "This expected index should be in the indexes in DB"