Skip to content

Commit

Permalink
sql module produces LiteralStrings, not strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Dec 16, 2023
1 parent 76c7c86 commit 5f9e3af
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions procrastinate/sql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re
import sys
from typing import Dict
from typing import Dict, cast

from typing_extensions import LiteralString

# https://github.com/pypa/twine/pull/551
if sys.version_info[:2] < (3, 9): # coverage: exclude
Expand All @@ -11,21 +13,24 @@
QUERIES_REGEX = re.compile(r"(?:\n|^)-- ([a-z0-9_]+) --\n(?:-- .+\n)*", re.MULTILINE)


def parse_query_file(query_file: str) -> Dict["str", "str"]:
def parse_query_file(query_file: str) -> Dict["str", LiteralString]:
split = iter(QUERIES_REGEX.split(query_file))
next(split) # Consume the header of the file
result = {}
try:
while True:
key = next(split)
value = next(split).strip()
result[key] = value
# procrastinate takes full responsibility for the queries, we
# can safely vouch for them being as safe as if they were
# defined in the code itself.
result[key] = cast(LiteralString, value)
except StopIteration:
pass
return result


def get_queries() -> Dict["str", "str"]:
def get_queries() -> Dict["str", LiteralString]:
return parse_query_file(
(importlib_resources.files("procrastinate.sql") / "queries.sql").read_text(
encoding="utf-8"
Expand Down

0 comments on commit 5f9e3af

Please sign in to comment.