Skip to content

Commit cf80f43

Browse files
grieve54706goldmedal
authored andcommitted
Adjust Ruff lint (#660)
1 parent f855358 commit cf80f43

File tree

13 files changed

+110
-28
lines changed

13 files changed

+110
-28
lines changed

ibis-server/app/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Config:
88

99
def __new__(cls):
1010
if cls._instance is None:
11-
cls._instance = super(Config, cls).__new__(cls)
11+
cls._instance = super().__new__(cls)
1212
return cls._instance
1313

1414
def __init__(self):

ibis-server/app/logger.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def log_dto(f):
1515

1616
@wraps(f)
1717
def wrapper(*args, **kwargs):
18-
logger.debug(f'DTO: {kwargs["dto"]}')
18+
logger.debug("DTO: %s", kwargs["dto"])
1919
return f(*args, **kwargs)
2020

2121
return wrapper

ibis-server/app/mdl/analyzer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ def analyze(manifest_str: str, sql: str) -> list[dict]:
1616
)
1717
return r.json() if r.status_code == httpx.codes.OK else r.raise_for_status()
1818
except httpx.ConnectError as e:
19-
raise ConnectionError(f"Can not connect to Wren Engine: {e}")
19+
raise ConnectionError(f"Can not connect to Wren Engine: {e}") from e

ibis-server/app/mdl/rewriter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def rewrite(self, sql: str) -> str:
3030
rewritten_sql = (
3131
r.text if r.status_code == httpx.codes.OK else r.raise_for_status()
3232
)
33-
logger.debug(f"Rewritten SQL: {rewritten_sql}")
33+
logger.debug("Rewritten SQL: %s", rewritten_sql)
3434
return (
3535
rewritten_sql
3636
if self.data_source is None
@@ -43,5 +43,5 @@ def transpile(self, rewritten_sql: str) -> str:
4343
transpiled_sql = sqlglot.transpile(
4444
rewritten_sql, read="trino", write=self.data_source.name
4545
)[0]
46-
logger.debug(f"Translated SQL: {transpiled_sql}")
46+
logger.debug("Translated SQL: %s", transpiled_sql)
4747
return transpiled_sql

ibis-server/app/model/__init__.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from typing import Union
4-
53
from pydantic import BaseModel, Field
64

75
manifest_str_field = Field(alias="manifestStr", description="Base64 manifest")
@@ -99,14 +97,14 @@ class SnowflakeConnectionInfo(BaseModel):
9997
) # Use `sf_schema` to avoid `schema` shadowing in BaseModel
10098

10199

102-
ConnectionInfo = Union[
103-
BigQueryConnectionInfo,
104-
ConnectionUrl,
105-
MSSqlConnectionInfo,
106-
MySqlConnectionInfo,
107-
PostgresConnectionInfo,
108-
SnowflakeConnectionInfo,
109-
]
100+
ConnectionInfo = (
101+
BigQueryConnectionInfo
102+
| ConnectionUrl
103+
| MSSqlConnectionInfo
104+
| MySqlConnectionInfo
105+
| PostgresConnectionInfo
106+
| SnowflakeConnectionInfo
107+
)
110108

111109

112110
class ValidateDTO(BaseModel):

ibis-server/app/model/connector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def dry_run(self, sql: str) -> None:
3131
rewritten_sql = Rewriter(self.manifest_str, self.data_source).rewrite(sql)
3232
self.connection.sql(rewritten_sql)
3333
except Exception as e:
34-
raise QueryDryRunError(f"Exception: {type(e)}, message: {str(e)}")
34+
raise QueryDryRunError(f"Exception: {type(e)}, message: {e!s}")
3535

3636

3737
class QueryDryRunError(Exception):

ibis-server/app/model/metadata/dto.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum
2-
from typing import Any, Optional
2+
from typing import Any
33

44
from pydantic import BaseModel, Field
55

@@ -69,22 +69,22 @@ class Column(BaseModel):
6969
name: str
7070
type: str
7171
notNull: bool
72-
description: Optional[str] = None
73-
properties: Optional[dict[str, Any]] = None
72+
description: str | None = None
73+
properties: dict[str, Any] | None = None
7474

7575

7676
class TableProperties(BaseModel):
77-
schema: Optional[str]
78-
catalog: Optional[str]
79-
table: Optional[str] # only table name without schema or catalog
77+
schema: str | None
78+
catalog: str | None
79+
table: str | None # only table name without schema or catalog
8080

8181

8282
class Table(BaseModel):
8383
name: str # unique table name (might contain schema name or catalog name as well)
8484
columns: list[Column]
85-
description: Optional[str] = None
85+
description: str | None = None
8686
properties: TableProperties = None
87-
primaryKey: Optional[str] = None
87+
primaryKey: str | None = None
8888

8989

9090
class ConstraintType(Enum):

ibis-server/app/model/validator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def validate(self, rule: str, parameters: dict[str, str]):
1717
except ValidationError as e:
1818
raise e
1919
except Exception as e:
20-
raise ValidationError(f"Unknown exception: {type(e)}, message: {str(e)}")
20+
raise ValidationError(f"Unknown exception: {type(e)}, message: {e!s}")
2121

2222
def _validate_column_is_valid(self, parameters: dict[str, str]):
2323
model_name = parameters.get("modelName")
@@ -32,7 +32,7 @@ def _validate_column_is_valid(self, parameters: dict[str, str]):
3232
f'SELECT "{column_name}" FROM "{model_name}" LIMIT 1'
3333
)
3434
except Exception as e:
35-
raise ValidationError(f"Exception: {type(e)}, message: {str(e)}")
35+
raise ValidationError(f"Exception: {type(e)}, message: {e!s}")
3636

3737

3838
class ValidationError(Exception):

ibis-server/app/util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pandas as pd
77

88

9-
def to_json(df: pd.DataFrame, column_dtypes: dict[str, str] = None) -> dict:
9+
def to_json(df: pd.DataFrame, column_dtypes: dict[str, str] | None) -> dict:
1010
if column_dtypes:
1111
_to_specific_types(df, column_dtypes)
1212
return _to_json_obj(df)

ibis-server/pyproject.toml

+85-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,94 @@ markers = [
4444
]
4545

4646
[tool.ruff]
47+
line-length = 88
4748
target-version = "py311"
4849

4950
[tool.ruff.lint]
50-
select = ["E4", "E7", "E9", "F", "I"]
51+
select = [
52+
"C4", # comprehensions
53+
"D", # pydocstyle
54+
"E", # pycodestyle
55+
"EXE", # flake8-executable
56+
"F", # pyflakes
57+
"FA", # flake8-future-annotations
58+
"G", # flake8-logging-format
59+
"FLY", # flynt (format string conversion)
60+
"I", # isort
61+
"ICN", # flake8-import-conventions
62+
"INP", # flake8-no-pep420 (implicit namespace packages)
63+
"ISC", # flake8-implicit-str-concat
64+
"PGH", # pygrep-hooks
65+
"PIE", # flake8-pie
66+
"PL", # pylint
67+
"RET", # flake8-return
68+
"RUF", # ruff-specific rules
69+
"SIM", # flake8-simplify
70+
"T10", # flake8-debugger
71+
"T20", # flake8-print
72+
"TID", # flake8-tidy-imports
73+
"UP", # pyupgrade
74+
"YTT", # flake8-2020
75+
]
76+
ignore = [
77+
"B008", # do not perform function calls in argument defaults
78+
"B028", # required stacklevel argument to warn
79+
"B904", # raise from e or raise from None in exception handlers
80+
"B905", # zip-without-explicit-strict
81+
"C408", # dict(...) as literal
82+
"C901", # too complex
83+
"D100", # public module
84+
"D101", # public class
85+
"D102", # public method
86+
"D103", # public function
87+
"D104", # public package
88+
"D105", # magic methods
89+
"D106", # nested class
90+
"D107", # init
91+
"D202", # blank lines after function docstring
92+
"D203", # blank line before class docstring
93+
"D213", # Multi-line docstring summary should start at the second line
94+
"D401", # Imperative mood
95+
"D402", # First line should not be the function's signature
96+
"D413", # Blank line required after last section
97+
"E501", # line-too-long, this is automatically enforced by ruff format
98+
"E731", # lambda-assignment
99+
"ISC001", # single line implicit string concat, handled by ruff format
100+
"PGH003", # blanket-type-ignore
101+
"PLC0105", # covariant type parameters should have a _co suffix
102+
"PLR0124", # name compared with self, e.g., a == a
103+
"PLR0911", # too many return statements
104+
"PLR0912", # too many branches
105+
"PLR0913", # too many arguments
106+
"PLR0915", # too many statements
107+
"PLR2004", # forces everything to be a constant
108+
"PLW2901", # overwriting loop variable
109+
"RET504", # unnecessary-assign, these are useful for debugging
110+
"RET505", # superfluous-else-return, stylistic choice
111+
"RET506", # superfluous-else-raise, stylistic choice
112+
"RET507", # superfluous-else-continue, stylistic choice
113+
"RET508", # superfluous-else-break, stylistic choice
114+
"RUF005", # splat instead of concat
115+
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
116+
"S101", # ignore "Use of `assert` detected"
117+
"SIM102", # nested ifs
118+
"SIM108", # convert everything to ternary operator
119+
"SIM114", # combine `if` branches using logical `or` operator
120+
"SIM116", # dictionary instead of `if` statements
121+
"SIM117", # nested with statements
122+
"SIM118", # remove .keys() calls from dictionaries
123+
"SIM300", # yoda conditions
124+
"UP007", # Optional[str] -> str | None
125+
"UP038", # non-pep604-isinstance, results in slower code
126+
"W191", # indentation contains tabs
127+
]
128+
# none of these codes will be automatically fixed by ruff
129+
unfixable = [
130+
"T201", # print statements
131+
"F401", # unused imports
132+
"RUF100", # unused noqa comments
133+
"F841", # unused variables
134+
]
51135

52136
[build-system]
53137
requires = ["poetry-core"]

ibis-server/tests/__init__.py

Whitespace-only changes.

ibis-server/tests/routers/__init__.py

Whitespace-only changes.

ibis-server/tests/routers/ibis/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)