Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scripts/generate_select.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from itertools import product
from pathlib import Path
from typing import List, Tuple
Expand Down Expand Up @@ -52,4 +53,11 @@ class Arg(BaseModel):

result = black.format_str(result, mode=black.Mode())

current_content = destiny_path.read_text()

if current_content != result and os.getenv("CHECK_JINJA"):
raise RuntimeError(
"sqlmodel/sql/expression.py content not update with Jinja2 template"
)

destiny_path.write_text(result)
2 changes: 2 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ mypy sqlmodel
flake8 sqlmodel tests docs_src
black sqlmodel tests docs_src --check
isort sqlmodel tests docs_src scripts --check-only
# TODO: move this to test.sh after deprecating Python 3.6
CHECK_JINJA=1 python scripts/generate_select.py
8 changes: 4 additions & 4 deletions sqlmodel/sql/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
if sys.version_info.minor >= 7:

class Select(_Select, Generic[_TSelect]):
pass
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, Generic[_TSelect]):
pass
inherit_cache = True

else:
from typing import GenericMeta # type: ignore
Expand All @@ -45,10 +45,10 @@ class GenericSelectMeta(GenericMeta, _Select.__class__): # type: ignore
pass

class _Py36Select(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):
pass
inherit_cache = True

class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):
pass
inherit_cache = True

# Cast them for editors to work correctly, from several tricks tried, this works
# for both VS Code and PyCharm
Expand Down