Skip to content

Commit 9547791

Browse files
committed
ruff
1 parent 4574f03 commit 9547791

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

pyproject.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ module = "pytsql.grammar.*"
7373
follow_imports = "silent"
7474

7575
[tool.ruff]
76-
ignore = ["E501", "N803", "N806"]
7776
line-length = 88
77+
78+
[tool.ruff.lint]
79+
ignore = ["E501", "N803", "N806"]
7880
select = [
7981
# pyflakes
8082
"F",
@@ -89,5 +91,5 @@ select = [
8991
]
9092
exclude=["src/pytsql/grammar/**/*.py"]
9193

92-
[tool.ruff.isort]
94+
[tool.ruff.lint.isort]
9395
known-first-party = ["pytsql"]

src/pytsql/tsql.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import warnings
44
from pathlib import Path
55
from re import Match
6-
from typing import Any, Dict, List, Optional, Union
6+
from typing import Any, Optional, Union
77

88
import antlr4.tree.Tree
99
import sqlalchemy
@@ -28,7 +28,7 @@ def _code(path: Union[str, Path], encoding: str) -> str:
2828
return "\n".join(fh.readlines())
2929

3030

31-
def _process_replacement(line: str, parameters: Dict[str, Any]) -> str:
31+
def _process_replacement(line: str, parameters: dict[str, Any]) -> str:
3232
"""Appropriately replace a single <replace> statement."""
3333
new_line = line.format(**parameters)
3434
if None in parameters.values():
@@ -42,7 +42,7 @@ def _process_replacement(line: str, parameters: Dict[str, Any]) -> str:
4242

4343
def _parametrize(
4444
source: str,
45-
parameters: Dict[str, Any],
45+
parameters: dict[str, Any],
4646
start: str = _REPLACE_START,
4747
end: str = _REPLACE_END,
4848
) -> str:
@@ -93,7 +93,7 @@ def __init__(self):
9393
# session information is lost after the execution of a batch.
9494
# We therefore need to manually prepend it to all following
9595
# batches.
96-
self.dynamics: List[str] = []
96+
self.dynamics: list[str] = []
9797

9898
def visit(
9999
self, tree: TSqlParser.Sql_clausesContext, prepend_dynamics: bool = True
@@ -112,7 +112,7 @@ def visit(
112112

113113
return " ".join(dynamics + chunks)
114114

115-
def visitChildren(self, node: antlr4.ParserRuleContext) -> List[str]: # noqa: N802
115+
def visitChildren(self, node: antlr4.ParserRuleContext) -> list[str]: # noqa: N802
116116
if isinstance(node, TSqlParser.Print_statementContext):
117117
# Print statements are replaced by inserts into a temporary table so that they can be evaluated
118118
# at the right time and fetched afterwards.
@@ -129,15 +129,15 @@ def visitChildren(self, node: antlr4.ParserRuleContext) -> List[str]: # noqa: N
129129

130130
return result
131131

132-
def visitTerminal(self, node: antlr4.TerminalNode) -> List[str]: # noqa: N802
132+
def visitTerminal(self, node: antlr4.TerminalNode) -> list[str]: # noqa: N802
133133
return [str(node)]
134134

135-
def defaultResult(self) -> List[str]: # noqa: N802
135+
def defaultResult(self) -> list[str]: # noqa: N802
136136
return []
137137

138138
def aggregateResult( # noqa: N802
139-
self, aggregate: List[str], next_result: List[str]
140-
) -> List[str]:
139+
self, aggregate: list[str], next_result: list[str]
140+
) -> list[str]:
141141
return aggregate + next_result
142142

143143

@@ -158,7 +158,7 @@ def syntaxError( # noqa: N802
158158
raise ValueError(f"Error parsing SQL script: {error_message}")
159159

160160

161-
def _split(code: str, isolate_top_level_statements: bool = True) -> List[str]:
161+
def _split(code: str, isolate_top_level_statements: bool = True) -> list[str]:
162162
if not USE_CPP_IMPLEMENTATION:
163163
warnings.warn(
164164
"Can not find C++ version of the parser, Python version will be used instead."
@@ -215,7 +215,7 @@ def _fetch_and_clear_prints(conn: Connection):
215215
def executes(
216216
code: str,
217217
engine: sqlalchemy.engine.Engine,
218-
parameters: Optional[Dict[str, Any]] = None,
218+
parameters: Optional[dict[str, Any]] = None,
219219
isolate_top_level_statements=True,
220220
) -> None:
221221
"""Execute a given sql string through a sqlalchemy.engine.Engine connection.
@@ -250,7 +250,7 @@ def executes(
250250
def execute(
251251
path: Union[str, Path],
252252
engine: sqlalchemy.engine.Engine,
253-
parameters: Optional[Dict[str, Any]] = None,
253+
parameters: Optional[dict[str, Any]] = None,
254254
isolate_top_level_statements=True,
255255
encoding: str = "utf-8",
256256
) -> None:

tests/unit/test_py_vs_cpp.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import inspect
22
import re
3-
from typing import List
43
from unittest import mock
54

65
import pytest
@@ -36,7 +35,7 @@ def seed():
3635
GROUP BY nr, short_nr;"""
3736

3837

39-
def get_rule_labels(context_cls: ParserRuleContext) -> List[str]:
38+
def get_rule_labels(context_cls: ParserRuleContext) -> list[str]:
4039
init_func = context_cls.__init__
4140

4241
# Detect any context/token labels from the init function's assignments

0 commit comments

Comments
 (0)