Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ python = "^3.10"
sqlparse = ">=0.6.0"

[tool.poetry.group.dev.dependencies]
ruff = ">=0.15.17,<0.16.0"
ruff = ">=0.16.8,<0.17.0"
mypy = "^2.3.1"
pytest = "^9.1.1"
poethepoet = ">=0.48.0,<0.49.0"
Expand Down Expand Up @@ -131,21 +131,21 @@ select = [
]
ignore = [
# NOTE(charly): line-length is up to the formatter
"E501",
# NOTE(charly): `one-blank-line-before-class` (D203) and
# `no-blank-line-before-class` (D211) are incompatible
"D203",
"line-too-long",
# NOTE(charly): `incorrect-blank-line-before-class` (D203) and
# `blank-line-before-class` (D211) are incompatible
"incorrect-blank-line-before-class",
# NOTE(charly): `multi-line-summary-first-line` (D212) and
# `multi-line-summary-second-line` (D213) are incompatible
"D213",
"multi-line-summary-second-line",
# Single-module library, __init__.py is the main module
"RUF067",
"non-empty-init-module",
# SQL files are always UTF-8
"PLW1514",
"unspecified-encoding",
]

[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = ["S101", "D"]
"tests/**/*.py" = ["assert", "D"]

[tool.ruff.lint.isort]
force-single-line = true
Expand Down
30 changes: 15 additions & 15 deletions sql_compare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,30 @@ def __repr__(self) -> str:

@property
def hash(self) -> str:
"""Return the normalized token value."""
"""The normalized token value."""
return str(self.token.normalized)

@property
def ignore(self) -> bool:
"""Return whether the token should be ignored."""
"""Whether the token should be ignored."""
return self.token.is_whitespace or self.is_comment

@property
def is_comment(self) -> bool:
"""Return whether the token is a comment."""
"""Whether the token is a comment."""
return isinstance(self.token, sqlparse.sql.Comment)

@property
def is_separator(self) -> bool:
"""Return whether the token is a separator."""
"""Whether the token is a separator."""
return bool(
self.token.ttype == sqlparse.tokens.Punctuation
and self.token.normalized == ",",
)

@property
def str_tokens(self) -> list[str]:
"""Return the token value."""
"""The token value, or nothing if it is blank."""
if self.hash.strip():
return [self.hash]
return []
Expand All @@ -141,22 +141,22 @@ def __hash__(self) -> int:

@property
def hash(self) -> str:
"""Return the hash of the `TokenList` instance."""
"""The hash of the `TokenList` instance."""
return "".join(t.hash for t in self.tokens if not t.ignore)

@property
def ignore(self) -> bool:
"""Return whether the token list should be ignored."""
"""Whether the token list should be ignored."""
return self.is_comment

@property
def is_comment(self) -> bool:
"""Return whether the token list is a comment."""
"""Whether the token list is a comment."""
return isinstance(self.token_list, sqlparse.sql.Comment)

@property
def tokens(self) -> Generator[Token | TokenList, None, None]:
"""Yield relevant tokens in a deterministic order."""
"""Relevant tokens, in a deterministic order."""
for token in self.token_list.tokens:
if token.is_group:
if UnorderedTokenList.is_unordered(token, self.statement_type):
Expand All @@ -168,15 +168,15 @@ def tokens(self) -> Generator[Token | TokenList, None, None]:

@property
def statement_type(self) -> str:
"""Return the type of SQL statement."""
"""The type of SQL statement."""
if self.parent:
return self.parent.statement_type

return Statement.UNKNOWN_TYPE

@property
def str_tokens(self) -> list[str]:
"""Return the reconstructed SQL statement from tokens as a list of strings."""
"""The reconstructed SQL statement from tokens, as a list of strings."""
return [t.hash for t in self.tokens if not t.ignore]


Expand Down Expand Up @@ -212,7 +212,7 @@ class Statement(TokenList):

@property
def statement_type(self) -> str:
"""Return the type of SQL statement."""
"""The type of SQL statement."""
keywords: list[str] = [
t.normalized
for t in self.token_list.tokens
Expand Down Expand Up @@ -252,7 +252,7 @@ def _leading_unlexed_verb(self) -> list[str]:

@property
def str_tokens(self) -> list[str]:
"""Return the reconstructed SQL statement from tokens as a list of strings."""
"""The reconstructed SQL statement from tokens, as a list of strings."""
return [t for token in self.tokens for t in token.str_tokens]


Expand All @@ -271,7 +271,7 @@ def is_unordered(token_list: sqlparse.sql.TokenList, statement_type: str) -> boo

@property
def tokens(self) -> Generator[Token | TokenList, None, None]:
"""Yield relevant tokens in a deterministic order."""
"""Relevant tokens, in a deterministic order."""
filtered_tokens = [t for t in self.flatten_tokens if not t.ignore]

# Split punctuations and identifiers (columns, types, etc.)
Expand All @@ -289,7 +289,7 @@ def tokens(self) -> Generator[Token | TokenList, None, None]:

@property
def flatten_tokens(self) -> Generator[Token, None, None]:
"""Yield all tokens in the token tree."""
"""All tokens in the token tree."""
yield from (Token(t) for t in self.token_list.flatten()) # type: ignore[no-untyped-call]

@staticmethod
Expand Down
Loading