♻️ Update expresion.py
, sync from Jinja2 template, implement inherit_cache
to solve errors like: SAWarning: Class SelectOfScalar will not make use of SQL compilation caching
(#422)
This commit is contained in:
parent
f232166db5
commit
b51ebaf658
@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
from itertools import product
|
from itertools import product
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
@ -52,4 +53,11 @@ result = (
|
|||||||
|
|
||||||
result = black.format_str(result, mode=black.Mode())
|
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)
|
destiny_path.write_text(result)
|
||||||
|
@ -7,3 +7,5 @@ mypy sqlmodel
|
|||||||
flake8 sqlmodel tests docs_src
|
flake8 sqlmodel tests docs_src
|
||||||
black sqlmodel tests docs_src --check
|
black sqlmodel tests docs_src --check
|
||||||
isort sqlmodel tests docs_src scripts --check-only
|
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
|
||||||
|
@ -29,14 +29,14 @@ _TSelect = TypeVar("_TSelect")
|
|||||||
if sys.version_info.minor >= 7:
|
if sys.version_info.minor >= 7:
|
||||||
|
|
||||||
class Select(_Select, Generic[_TSelect]):
|
class Select(_Select, Generic[_TSelect]):
|
||||||
pass
|
inherit_cache = True
|
||||||
|
|
||||||
# This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different
|
# 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
|
# 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
|
# entity, so the result will be converted to a scalar by default. This way writing
|
||||||
# for loops on the results will feel natural.
|
# for loops on the results will feel natural.
|
||||||
class SelectOfScalar(_Select, Generic[_TSelect]):
|
class SelectOfScalar(_Select, Generic[_TSelect]):
|
||||||
pass
|
inherit_cache = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
from typing import GenericMeta # type: ignore
|
from typing import GenericMeta # type: ignore
|
||||||
@ -45,10 +45,10 @@ else:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class _Py36Select(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):
|
class _Py36Select(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):
|
||||||
pass
|
inherit_cache = True
|
||||||
|
|
||||||
class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):
|
class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):
|
||||||
pass
|
inherit_cache = True
|
||||||
|
|
||||||
# Cast them for editors to work correctly, from several tricks tried, this works
|
# Cast them for editors to work correctly, from several tricks tried, this works
|
||||||
# for both VS Code and PyCharm
|
# for both VS Code and PyCharm
|
||||||
|
Loading…
x
Reference in New Issue
Block a user