]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
♻️ Update `expresion.py`, sync from Jinja2 template, implement `inherit_cache` to...
authorSebastián Ramírez <tiangolo@gmail.com>
Mon, 29 Aug 2022 09:44:08 +0000 (11:44 +0200)
committerGitHub <noreply@github.com>
Mon, 29 Aug 2022 09:44:08 +0000 (11:44 +0200)
scripts/generate_select.py
scripts/lint.sh
sqlmodel/sql/expression.py

index b66a1673c4f126ea2a93f87cf943a60b779ec1d3..f8aa30023fad1d3d251b8e7b920fcd27aa0aa16c 100644 (file)
@@ -1,3 +1,4 @@
+import os
 from itertools import product
 from pathlib import Path
 from typing import List, Tuple
@@ -52,4 +53,11 @@ result = (
 
 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)
index 4191d90f1f69bbf0539398ca06a6ab2934794664..02568cda6b58560a9eed413b4338cf1eaf07bee7 100755 (executable)
@@ -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
index e7317bcdd8edc52ac180fdb6e5e7dfdb17caf635..31c0bc1a1e3b252646d8bed267797917ccbda364 100644 (file)
@@ -29,14 +29,14 @@ _TSelect = TypeVar("_TSelect")
 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
@@ -45,10 +45,10 @@ else:
         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