Skip to content

Commit def1617

Browse files
authored
Merge pull request #10 from waketzheng/fix-enums-not-quoted
Fix enums not quoted
2 parents 2054a6a + fa41660 commit def1617

22 files changed

+1795
-1514
lines changed

.github/workflows/ci.yml

+13-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@ on: [ push, pull_request ]
33
jobs:
44
ci:
55
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
python-version: [3.8, 3.9, "3.10", 3.11, 3.12, 3.13]
69
steps:
7-
- uses: actions/checkout@v2
8-
- uses: actions/setup-python@v2
10+
- uses: actions/cache@v4
911
with:
10-
python-version: "3.x"
12+
path: ~/.cache/pip
13+
key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}
14+
restore-keys: |
15+
${{ runner.os }}-pip-
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
allow-prereleases: true
1121
- name: Install and configure Poetry
1222
run: |
1323
pip install -U pip poetry
1424
poetry config virtualenvs.create false
15-
- name: Install deps
16-
run: make deps
1725
- name: Run CI
1826
run: make ci

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## 0.2
44

5+
### 0.2.2
6+
- Fix enums not quoted. (#7)
7+
- Drop python3.7 support
8+
- Move all custom Exception class to `pypika.exceptions`
9+
- Apply bandit check in ci
10+
- Pass mypy check and add it to ci
11+
512
### 0.2.1
613
- Fix stringification of datetime objects
714

Makefile

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
checkfiles = pypika/ tests/ conftest.py
2-
black_opts = -l 100 -t py37
2+
black_opts = -l 100 -t py38
33
py_warn = PYTHONDEVMODE=1
44

55
up:
@@ -8,25 +8,30 @@ up:
88
deps:
99
@poetry install
1010

11-
check: deps build
11+
check: build _check
12+
_check:
1213
ifneq ($(shell which black),)
1314
black --check $(black_opts) $(checkfiles) || (echo "Please run 'make style' to auto-fix style issues" && false)
1415
endif
15-
ruff $(checkfiles)
16+
ruff check $(checkfiles)
17+
bandit -c pyproject.toml -r $(checkfiles)
18+
mypy $(checkfiles)
1619
twine check dist/*
1720

18-
test: deps
21+
test: deps _test
22+
_test:
1923
$(py_warn) pytest
2024

21-
ci: check test
25+
ci: build _check _test
2226

23-
style: deps
27+
style: deps _style
28+
_style:
2429
isort -src $(checkfiles)
2530
black $(black_opts) $(checkfiles)
2631

2732
build: deps
2833
rm -fR dist/
2934
poetry build
3035

31-
publish: deps build
36+
publish: build
3237
twine upload dist/*

poetry.lock

+705-634
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pypika/__init__.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
from pypika.dialects import MSSQLQuery, MySQLQuery, OracleQuery, PostgreSQLQuery, SQLLiteQuery
22
from pypika.enums import DatePart, Dialects, JoinType, Order
3+
from pypika.exceptions import (
4+
CaseException,
5+
FunctionException,
6+
GroupingException,
7+
JoinException,
8+
QueryException,
9+
RollupException,
10+
SetOperationException,
11+
)
312
from pypika.queries import AliasedQuery, Column, Database, Query, Schema, Table
413
from pypika.queries import make_columns as Columns
514
from pypika.queries import make_tables as Tables
@@ -26,15 +35,6 @@
2635
SystemTimeValue,
2736
Tuple,
2837
)
29-
from pypika.utils import (
30-
CaseException,
31-
FunctionException,
32-
GroupingException,
33-
JoinException,
34-
QueryException,
35-
RollupException,
36-
SetOperationException,
37-
)
3838

3939
NULL = NullValue()
4040
SYSTEM_TIME = SystemTimeValue()

pypika/analytics.py

+41-40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Package for SQL analytic functions wrappers
33
"""
4+
45
from pypika.terms import AnalyticFunction, IgnoreNullsAnalyticFunction, WindowFrameAnalyticFunction
56

67

@@ -16,100 +17,100 @@ class Following(WindowFrameAnalyticFunction.Edge):
1617

1718

1819
class Rank(AnalyticFunction):
19-
def __init__(self, **kwargs):
20-
super(Rank, self).__init__("RANK", **kwargs)
20+
def __init__(self, **kwargs) -> None:
21+
super().__init__("RANK", **kwargs)
2122

2223

2324
class DenseRank(AnalyticFunction):
24-
def __init__(self, **kwargs):
25-
super(DenseRank, self).__init__("DENSE_RANK", **kwargs)
25+
def __init__(self, **kwargs) -> None:
26+
super().__init__("DENSE_RANK", **kwargs)
2627

2728

2829
class RowNumber(AnalyticFunction):
29-
def __init__(self, **kwargs):
30-
super(RowNumber, self).__init__("ROW_NUMBER", **kwargs)
30+
def __init__(self, **kwargs) -> None:
31+
super().__init__("ROW_NUMBER", **kwargs)
3132

3233

3334
class NTile(AnalyticFunction):
34-
def __init__(self, term, **kwargs):
35-
super(NTile, self).__init__("NTILE", term, **kwargs)
35+
def __init__(self, term, **kwargs) -> None:
36+
super().__init__("NTILE", term, **kwargs)
3637

3738

3839
class FirstValue(WindowFrameAnalyticFunction, IgnoreNullsAnalyticFunction):
39-
def __init__(self, *terms, **kwargs):
40-
super(FirstValue, self).__init__("FIRST_VALUE", *terms, **kwargs)
40+
def __init__(self, *terms, **kwargs) -> None:
41+
super().__init__("FIRST_VALUE", *terms, **kwargs)
4142

4243

4344
class LastValue(WindowFrameAnalyticFunction, IgnoreNullsAnalyticFunction):
44-
def __init__(self, *terms, **kwargs):
45-
super(LastValue, self).__init__("LAST_VALUE", *terms, **kwargs)
45+
def __init__(self, *terms, **kwargs) -> None:
46+
super().__init__("LAST_VALUE", *terms, **kwargs)
4647

4748

4849
class Median(AnalyticFunction):
49-
def __init__(self, term, **kwargs):
50-
super(Median, self).__init__("MEDIAN", term, **kwargs)
50+
def __init__(self, term, **kwargs) -> None:
51+
super().__init__("MEDIAN", term, **kwargs)
5152

5253

5354
class Avg(WindowFrameAnalyticFunction):
54-
def __init__(self, term, **kwargs):
55-
super(Avg, self).__init__("AVG", term, **kwargs)
55+
def __init__(self, term, **kwargs) -> None:
56+
super().__init__("AVG", term, **kwargs)
5657

5758

5859
class StdDev(WindowFrameAnalyticFunction):
59-
def __init__(self, term, **kwargs):
60-
super(StdDev, self).__init__("STDDEV", term, **kwargs)
60+
def __init__(self, term, **kwargs) -> None:
61+
super().__init__("STDDEV", term, **kwargs)
6162

6263

6364
class StdDevPop(WindowFrameAnalyticFunction):
64-
def __init__(self, term, **kwargs):
65-
super(StdDevPop, self).__init__("STDDEV_POP", term, **kwargs)
65+
def __init__(self, term, **kwargs) -> None:
66+
super().__init__("STDDEV_POP", term, **kwargs)
6667

6768

6869
class StdDevSamp(WindowFrameAnalyticFunction):
69-
def __init__(self, term, **kwargs):
70-
super(StdDevSamp, self).__init__("STDDEV_SAMP", term, **kwargs)
70+
def __init__(self, term, **kwargs) -> None:
71+
super().__init__("STDDEV_SAMP", term, **kwargs)
7172

7273

7374
class Variance(WindowFrameAnalyticFunction):
74-
def __init__(self, term, **kwargs):
75-
super(Variance, self).__init__("VARIANCE", term, **kwargs)
75+
def __init__(self, term, **kwargs) -> None:
76+
super().__init__("VARIANCE", term, **kwargs)
7677

7778

7879
class VarPop(WindowFrameAnalyticFunction):
79-
def __init__(self, term, **kwargs):
80-
super(VarPop, self).__init__("VAR_POP", term, **kwargs)
80+
def __init__(self, term, **kwargs) -> None:
81+
super().__init__("VAR_POP", term, **kwargs)
8182

8283

8384
class VarSamp(WindowFrameAnalyticFunction):
84-
def __init__(self, term, **kwargs):
85-
super(VarSamp, self).__init__("VAR_SAMP", term, **kwargs)
85+
def __init__(self, term, **kwargs) -> None:
86+
super().__init__("VAR_SAMP", term, **kwargs)
8687

8788

8889
class Count(WindowFrameAnalyticFunction):
89-
def __init__(self, term, **kwargs):
90-
super(Count, self).__init__("COUNT", term, **kwargs)
90+
def __init__(self, term, **kwargs) -> None:
91+
super().__init__("COUNT", term, **kwargs)
9192

9293

9394
class Sum(WindowFrameAnalyticFunction):
94-
def __init__(self, term, **kwargs):
95-
super(Sum, self).__init__("SUM", term, **kwargs)
95+
def __init__(self, term, **kwargs) -> None:
96+
super().__init__("SUM", term, **kwargs)
9697

9798

9899
class Max(WindowFrameAnalyticFunction):
99-
def __init__(self, term, **kwargs):
100-
super(Max, self).__init__("MAX", term, **kwargs)
100+
def __init__(self, term, **kwargs) -> None:
101+
super().__init__("MAX", term, **kwargs)
101102

102103

103104
class Min(WindowFrameAnalyticFunction):
104-
def __init__(self, term, **kwargs):
105-
super(Min, self).__init__("MIN", term, **kwargs)
105+
def __init__(self, term, **kwargs) -> None:
106+
super().__init__("MIN", term, **kwargs)
106107

107108

108109
class Lag(AnalyticFunction):
109-
def __init__(self, *args, **kwargs):
110-
super(Lag, self).__init__("LAG", *args, **kwargs)
110+
def __init__(self, *args, **kwargs) -> None:
111+
super().__init__("LAG", *args, **kwargs)
111112

112113

113114
class Lead(AnalyticFunction):
114-
def __init__(self, *args, **kwargs):
115-
super(Lead, self).__init__("LEAD", *args, **kwargs)
115+
def __init__(self, *args, **kwargs) -> None:
116+
super().__init__("LEAD", *args, **kwargs)

pypika/dialects/mssql.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from typing import Any, Union
1+
from __future__ import annotations
2+
3+
from typing import Any
24

35
from pypika.enums import Dialects
6+
from pypika.exceptions import QueryException
47
from pypika.queries import Query, QueryBuilder
5-
from pypika.utils import QueryException, builder
8+
from pypika.utils import builder
69

710

811
class MSSQLQuery(Query):
@@ -20,10 +23,10 @@ class MSSQLQueryBuilder(QueryBuilder):
2023

2124
def __init__(self, **kwargs: Any) -> None:
2225
super().__init__(dialect=Dialects.MSSQL, **kwargs)
23-
self._top = None
26+
self._top: int | None = None
2427

2528
@builder
26-
def top(self, value: Union[str, int]) -> "MSSQLQueryBuilder":
29+
def top(self, value: str | int) -> MSSQLQueryBuilder: # type:ignore[return]
2730
"""
2831
Implements support for simple TOP clauses.
2932
@@ -37,7 +40,7 @@ def top(self, value: Union[str, int]) -> "MSSQLQueryBuilder":
3740
raise QueryException("TOP value must be an integer")
3841

3942
@builder
40-
def fetch_next(self, limit: int) -> "MSSQLQueryBuilder":
43+
def fetch_next(self, limit: int) -> MSSQLQueryBuilder: # type:ignore[return]
4144
# Overridden to provide a more domain-specific API for T-SQL users
4245
self._limit = limit
4346

0 commit comments

Comments
 (0)