Skip to content

Commit 48ddc61

Browse files
committed
fix some linting errors
1 parent 60318b4 commit 48ddc61

File tree

10 files changed

+74
-53
lines changed

10 files changed

+74
-53
lines changed

sqlmodel/engine/create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ def create_engine(
136136
if not isinstance(query_cache_size, _DefaultPlaceholder):
137137
current_kwargs["query_cache_size"] = query_cache_size
138138
current_kwargs.update(kwargs)
139-
return _create_engine(url, **current_kwargs) # type: ignore
139+
return _create_engine(url, **current_kwargs)

sqlmodel/engine/result.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
from typing import Generic, Iterator, List, Optional, TypeVar
1+
from typing import Generic, Iterator, List, Optional, Sequence, TypeVar
22

33
from sqlalchemy.engine.result import Result as _Result
44
from sqlalchemy.engine.result import ScalarResult as _ScalarResult
55

66
_T = TypeVar("_T")
77

88

9-
class ScalarResult(_ScalarResult, Generic[_T]):
10-
def all(self) -> List[_T]:
9+
class ScalarResult(_ScalarResult[_T], Generic[_T]):
10+
def all(self) -> Sequence[_T]:
1111
return super().all()
1212

13-
def partitions(self, size: Optional[int] = None) -> Iterator[List[_T]]:
13+
def partitions(self, size: Optional[int] = None) -> Iterator[Sequence[_T]]:
1414
return super().partitions(size)
1515

16-
def fetchall(self) -> List[_T]:
16+
def fetchall(self) -> Sequence[_T]:
1717
return super().fetchall()
1818

19-
def fetchmany(self, size: Optional[int] = None) -> List[_T]:
19+
def fetchmany(self, size: Optional[int] = None) -> Sequence[_T]:
2020
return super().fetchmany(size)
2121

2222
def __iter__(self) -> Iterator[_T]:
2323
return super().__iter__()
2424

2525
def __next__(self) -> _T:
26-
return super().__next__() # type: ignore
26+
return super().__next__()
2727

2828
def first(self) -> Optional[_T]:
2929
return super().first()
@@ -32,10 +32,10 @@ def one_or_none(self) -> Optional[_T]:
3232
return super().one_or_none()
3333

3434
def one(self) -> _T:
35-
return super().one() # type: ignore
35+
return super().one()
3636

3737

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

@@ -76,4 +76,4 @@ def one(self) -> _T: # type: ignore
7676
return super().one() # type: ignore
7777

7878
def scalar(self) -> Optional[_T]:
79-
return super().scalar()
79+
return super().scalar() # type: ignore

sqlmodel/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry
478478
__sqlmodel_relationships__: ClassVar[Dict[str, RelationshipProperty]] # type: ignore
479479
__name__: ClassVar[str]
480480
metadata: ClassVar[MetaData]
481-
__allow_unmapped__ = True # https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#migration-20-step-six
481+
__allow_unmapped__ = True # https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#migration-20-step-six
482482

483483
class Config:
484484
orm_mode = True
@@ -522,7 +522,7 @@ def __setattr__(self, name: str, value: Any) -> None:
522522
return
523523
else:
524524
# Set in SQLAlchemy, before Pydantic to trigger events and updates
525-
if getattr(self.__config__, "table", False) and is_instrumented(self, name):
525+
if getattr(self.__config__, "table", False) and is_instrumented(self, name): # type: ignore
526526
set_attribute(self, name, value)
527527
# Set in Pydantic model to trigger possible validation changes, only for
528528
# non relationship values

sqlmodel/orm/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def query(self, *entities: Any, **kwargs: Any) -> "_Query[Any]":
118118
Or otherwise you might want to use `session.execute()` instead of
119119
`session.query()`.
120120
"""
121-
return super().query(*entities, **kwargs)
121+
return super().query(*entities, **kwargs) # type: ignore
122122

123123
def get(
124124
self,

sqlmodel/sql/expression.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,15 @@
2626

2727
# Workaround Generics incompatibility in Python 3.6
2828
# Ref: https://github.com/python/typing/issues/449#issuecomment-316061322
29-
if sys.version_info.minor >= 7:
29+
class Select(_Select[_TSelect], Generic[_TSelect]):
30+
inherit_cache = True
3031

31-
class Select(_Select, Generic[_TSelect]):
32-
inherit_cache = True
33-
34-
# This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different
35-
# purpose. This is the same as a normal SQLAlchemy Select class where there's only one
36-
# entity, so the result will be converted to a scalar by default. This way writing
37-
# for loops on the results will feel natural.
38-
class SelectOfScalar(_Select, Generic[_TSelect]):
39-
inherit_cache = True
40-
41-
else:
42-
from typing import GenericMeta # type: ignore
43-
44-
class GenericSelectMeta(GenericMeta, _Select.__class__): # type: ignore
45-
pass
46-
47-
class _Py36Select(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):
48-
inherit_cache = True
49-
50-
class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):
51-
inherit_cache = True
52-
53-
# Cast them for editors to work correctly, from several tricks tried, this works
54-
# for both VS Code and PyCharm
55-
Select = cast("Select", _Py36Select) # type: ignore
56-
SelectOfScalar = cast("SelectOfScalar", _Py36SelectOfScalar) # type: ignore
32+
# This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different
33+
# purpose. This is the same as a normal SQLAlchemy Select class where there's only one
34+
# entity, so the result will be converted to a scalar by default. This way writing
35+
# for loops on the results will feel natural.
36+
class SelectOfScalar(_Select[_TSelect], Generic[_TSelect]):
37+
inherit_cache = True
5738

5839

5940
if TYPE_CHECKING: # pragma: no cover
@@ -427,4 +408,4 @@ def select(*entities: Any) -> Union[Select, SelectOfScalar]: # type: ignore
427408
def col(column_expression: Any) -> ColumnClause: # type: ignore
428409
if not isinstance(column_expression, (ColumnClause, Column, InstrumentedAttribute)):
429410
raise RuntimeError(f"Not a SQLAlchemy column: {column_expression}")
430-
return column_expression
411+
return column_expression # type: ignore

sqlmodel/sql/sqltypes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AutoString(types.TypeDecorator): # type: ignore
1616
def load_dialect_impl(self, dialect: Dialect) -> "types.TypeEngine[Any]":
1717
impl = cast(types.String, self.impl)
1818
if impl.length is None and dialect.name == "mysql":
19-
return dialect.type_descriptor(types.String(self.mysql_default_length)) # type: ignore
19+
return dialect.type_descriptor(types.String(self.mysql_default_length))
2020
return super().load_dialect_impl(dialect)
2121

2222

@@ -35,9 +35,9 @@ class GUID(types.TypeDecorator): # type: ignore
3535

3636
def load_dialect_impl(self, dialect: Dialect) -> TypeEngine: # type: ignore
3737
if dialect.name == "postgresql":
38-
return dialect.type_descriptor(UUID()) # type: ignore
38+
return dialect.type_descriptor(UUID())
3939
else:
40-
return dialect.type_descriptor(CHAR(32)) # type: ignore
40+
return dialect.type_descriptor(CHAR(32))
4141

4242
def process_bind_param(self, value: Any, dialect: Dialect) -> Optional[str]:
4343
if value is None:

tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,18 @@ def test_tutorial(clear_sqlmodel):
173173
insp: Inspector = inspect(mod.engine)
174174
indexes = insp.get_indexes(str(mod.Hero.__tablename__))
175175
expected_indexes = [
176-
{"name": "ix_hero_name", "column_names": ["name"], "unique": 0, 'dialect_options': {}},
177-
{"name": "ix_hero_age", "column_names": ["age"], "unique": 0, 'dialect_options': {}},
176+
{
177+
"name": "ix_hero_name",
178+
"column_names": ["name"],
179+
"unique": 0,
180+
"dialect_options": {},
181+
},
182+
{
183+
"name": "ix_hero_age",
184+
"column_names": ["age"],
185+
"unique": 0,
186+
"dialect_options": {},
187+
},
178188
]
179189
for index in expected_indexes:
180190
assert index in indexes, "This expected index should be in the indexes in DB"

tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,18 @@ def test_tutorial(clear_sqlmodel):
173173
insp: Inspector = inspect(mod.engine)
174174
indexes = insp.get_indexes(str(mod.Hero.__tablename__))
175175
expected_indexes = [
176-
{"name": "ix_hero_age", "column_names": ["age"], "unique": 0, 'dialect_options': {}},
177-
{"name": "ix_hero_name", "column_names": ["name"], "unique": 0, 'dialect_options': {}},
176+
{
177+
"name": "ix_hero_age",
178+
"column_names": ["age"],
179+
"unique": 0,
180+
"dialect_options": {},
181+
},
182+
{
183+
"name": "ix_hero_name",
184+
"column_names": ["name"],
185+
"unique": 0,
186+
"dialect_options": {},
187+
},
178188
]
179189
for index in expected_indexes:
180190
assert index in indexes, "This expected index should be in the indexes in DB"

tests/test_tutorial/test_indexes/test_tutorial001.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ def test_tutorial(clear_sqlmodel):
2525
insp: Inspector = inspect(mod.engine)
2626
indexes = insp.get_indexes(str(mod.Hero.__tablename__))
2727
expected_indexes = [
28-
{"name": "ix_hero_name", "column_names": ["name"], "unique": 0, 'dialect_options': {}},
29-
{"name": "ix_hero_age", "column_names": ["age"], "unique": 0, 'dialect_options': {}},
28+
{
29+
"name": "ix_hero_name",
30+
"column_names": ["name"],
31+
"unique": 0,
32+
"dialect_options": {},
33+
},
34+
{
35+
"name": "ix_hero_age",
36+
"column_names": ["age"],
37+
"unique": 0,
38+
"dialect_options": {},
39+
},
3040
]
3141
for index in expected_indexes:
3242
assert index in indexes, "This expected index should be in the indexes in DB"

tests/test_tutorial/test_indexes/test_tutorial006.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,18 @@ def test_tutorial(clear_sqlmodel):
2626
insp: Inspector = inspect(mod.engine)
2727
indexes = insp.get_indexes(str(mod.Hero.__tablename__))
2828
expected_indexes = [
29-
{"name": "ix_hero_name", "column_names": ["name"], "unique": 0, 'dialect_options': {}},
30-
{"name": "ix_hero_age", "column_names": ["age"], "unique": 0, 'dialect_options': {}},
29+
{
30+
"name": "ix_hero_name",
31+
"column_names": ["name"],
32+
"unique": 0,
33+
"dialect_options": {},
34+
},
35+
{
36+
"name": "ix_hero_age",
37+
"column_names": ["age"],
38+
"unique": 0,
39+
"dialect_options": {},
40+
},
3141
]
3242
for index in expected_indexes:
3343
assert index in indexes, "This expected index should be in the indexes in DB"

0 commit comments

Comments
 (0)