Skip to content

Commit 4d7a11c

Browse files
authored
Merge pull request #22 from baluyotraf/test/new-py
feat: support for python 3.13 and 3.14
2 parents d940b22 + 894101d commit 4d7a11c

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

.github/workflows/qa.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- ubuntu-latest
3434
- macos-latest
3535
- windows-latest
36-
python_version: ["3.9", "3.10", "3.11", "3.12"]
36+
python_version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
3737
runs-on: ${{ matrix.os }}
3838
steps:
3939
- uses: actions/checkout@v3

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ keywords = ["database", "SQL"]
2424
[tool.poetry.dependencies]
2525
python = "^3.9"
2626
pydantic = "^2.6.4"
27+
typing-extensions = "^4.15.0"
2728

2829
[tool.poetry.group.dev.dependencies]
2930
pyright = "^1.1.354"
@@ -48,10 +49,12 @@ testpaths = ["tests"]
4849
legacy_tox_ini = """
4950
[tox]
5051
min_version = 4.0
51-
env_list = py{39,310,311,312}
52+
env_list = py{39,310,311,312,313,314}
5253
5354
[gh]
5455
python =
56+
3.14 = py314
57+
3.13 = py313
5558
3.12 = py312
5659
3.11 = py311
5760
3.10 = py310

src/altqq/structs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pydantic.dataclasses as pdc
77
from pydantic import ConfigDict
8-
from typing_extensions import dataclass_transform
8+
from typing_extensions import dataclass_transform, get_annotations
99

1010
QUERY_ATTRIB = "__query__"
1111

@@ -34,12 +34,13 @@ class QueryMeta(type):
3434
"""
3535

3636
@staticmethod
37-
def _check_query_attribute(dataclass: "QueryMeta", dct: Dict[str, Any]):
37+
def _check_query_attribute(dataclass: "QueryMeta"):
3838
try:
3939
if isinstance(getattr(dataclass, QUERY_ATTRIB), str):
4040
return True
4141
except AttributeError:
42-
return QUERY_ATTRIB in dct["__annotations__"]
42+
annotations = get_annotations(dataclass)
43+
return QUERY_ATTRIB in annotations
4344

4445
return False
4546

@@ -57,8 +58,8 @@ def __new__(cls, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]):
5758
"""
5859
cls._resolve_calculated_fields(dct)
5960
dataclass = super().__new__(cls, name, bases, dct)
60-
if not cls._check_query_attribute(dataclass, dct):
61-
raise ValueError(f"A string {QUERY_ATTRIB} must be provided")
61+
if not cls._check_query_attribute(dataclass):
62+
raise ValueError(f"A {QUERY_ATTRIB} value or type hint must be provided.")
6263
return pdc.dataclass(dataclass, config=ConfigDict(arbitrary_types_allowed=True))
6364

6465

tests/test_query.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Tests the translations of queries."""
2+
3+
from typing import ClassVar
4+
5+
import altqq
6+
import pytest
7+
8+
9+
def test_query_subclass__no_annotations__raises_error():
10+
"""If subclass does not have any annotations, raise a ValueError."""
11+
with pytest.raises(ValueError):
12+
13+
class _(altqq.Query):
14+
pass
15+
16+
17+
def test_query_subclass__without__query__raises_error():
18+
"""If subclass has annotations, but no __query__, raise a ValueError."""
19+
with pytest.raises(ValueError):
20+
21+
class _(altqq.Query):
22+
props: int
23+
24+
25+
def test_query_subclass__query_defined__works():
26+
"""If subclass defines __query__ attribute, all is good."""
27+
28+
class _(altqq.Query):
29+
__query__ = "My query"
30+
31+
32+
def test_query_subclass__query_typed__works():
33+
"""If subclass defines __query__ with a type hint, all is good."""
34+
35+
class _(altqq.Query):
36+
__query__: ClassVar[str]

0 commit comments

Comments
 (0)