Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-rp committed Aug 16, 2024
1 parent 3fd92f0 commit 9c2ddf0
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 73 deletions.
4 changes: 1 addition & 3 deletions liquid/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class BuiltIn(Mapping[str, object]):
"""Mapping-like object for resolving built-in, dynamic objects."""

def __contains__(self, item: object) -> bool:
if item in ("now", "today"):
return True
return False
return item in ("now", "today")

def __getitem__(self, key: str) -> object:
if key == "now":
Expand Down
15 changes: 5 additions & 10 deletions liquid/expression.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Liquid expression objects."""

from __future__ import annotations

import sys
Expand Down Expand Up @@ -79,9 +80,7 @@ class Empty(Expression):
def __eq__(self, other: object) -> bool:
if isinstance(other, Empty):
return True
if isinstance(other, (list, dict, str)) and not other:
return True
return False
return isinstance(other, (list, dict, str)) and not other

def __repr__(self) -> str: # pragma: no cover
return "Empty()"
Expand All @@ -107,9 +106,7 @@ def __eq__(self, other: object) -> bool:
return True
if isinstance(other, (list, dict)) and not other:
return True
if isinstance(other, Blank):
return True
return False
return isinstance(other, Blank)

def __repr__(self) -> str: # pragma: no cover
return "Blank()"
Expand All @@ -131,9 +128,7 @@ class Continue(Expression):
__slots__ = ()

def __eq__(self, other: object) -> bool:
if isinstance(other, Continue):
return True
return False
return isinstance(other, Continue)

def __repr__(self) -> str: # pragma: no cover
return "Continue()"
Expand Down Expand Up @@ -1106,7 +1101,7 @@ def compare(left: object, op: str, right: object) -> bool: # noqa: PLR0911, PLR
right = right.__liquid__()

def _type_error(_left: object, _right: object) -> NoReturn:
if type(_left) != type(_right):
if type(_left) != type(_right): # noqa: E721
raise LiquidTypeError(f"invalid operator for types '{_left} {op} {_right}'")

raise LiquidTypeError(f"unknown operator: {type(_left)} {op} {type(_right)}")
Expand Down
1 change: 0 additions & 1 deletion liquid/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ def parse_filter(self, stream: TokenStream) -> expression.Filter:
filter_name = stream.current.value
stream.next_token()

#
args = []
kwargs = {}

Expand Down
107 changes: 57 additions & 50 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build-backend = "hatchling.build"
requires = ["hatchling"]

[project]
authors = [{name = "James Prior", email = "[email protected]"}]
authors = [{ name = "James Prior", email = "[email protected]" }]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand All @@ -18,7 +18,11 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = ["python-dateutil>=2.8.1", "typing-extensions>=4.2.0", "importlib-resources>=5.10.0"]
dependencies = [
"python-dateutil>=2.8.1",
"typing-extensions>=4.2.0",
"importlib-resources>=5.10.0",
]
description = "A Python engine for the Liquid template language."
dynamic = ["version"]
license = "MIT"
Expand Down Expand Up @@ -126,6 +130,56 @@ warn_unused_configs = true
warn_unused_ignores = false

[tool.ruff]

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

# Same as Black.
line-length = 88

# Assume Python 3.10.
target-version = "py310"

[tool.ruff.lint.isort]
force-single-line = true

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.per-file-ignores]
"liquid/__about__.py" = ["D100"]
"liquid/__init__.py" = ["D104", "I001"]
"liquid/builtin/filters/__init__.py" = ["D104", "I001"]
"liquid/builtin/loaders/__init__.py" = ["D104", "I001"]
"liquid/builtin/tags/__init__.py" = ["D104", "I001"]
"scripts/__init__.py" = ["D104", "I001"]
"tests/*" = ["D100", "D101", "D104", "D103", "D102", "D209", "D205", "SIM117"]

[tool.ruff.lint]
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

select = [
"A",
"ARG",
Expand Down Expand Up @@ -153,6 +207,7 @@ select = [
"TCH",
"YTT",
]

# TODO: review ignores
ignore = [
"S105",
Expand All @@ -169,51 +224,3 @@ ignore = [

fixable = ["I", "SIM", "D202"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

# Same as Black.
line-length = 88

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.10.
target-version = "py310"

[tool.ruff.isort]
force-single-line = true

[tool.ruff.pydocstyle]
convention = "google"

[tool.ruff.per-file-ignores]
"liquid/__about__.py" = ["D100"]
"liquid/__init__.py" = ["D104", "I001"]
"liquid/builtin/filters/__init__.py" = ["D104", "I001"]
"liquid/builtin/loaders/__init__.py" = ["D104", "I001"]
"liquid/builtin/tags/__init__.py" = ["D104", "I001"]
"scripts/__init__.py" = ["D104", "I001"]
"tests/*" = ["D100", "D101", "D104", "D103", "D102", "D209", "D205", "SIM117"]
13 changes: 4 additions & 9 deletions tests/filters/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test miscellaneous filter functions."""

import datetime
import decimal
import platform
Expand Down Expand Up @@ -32,9 +33,7 @@ def __init__(self, val):
self.val = val

def __eq__(self, other):
if isinstance(other, MockDrop) and self.val == other.val:
return True
return False
return bool(isinstance(other, MockDrop) and self.val == other.val)

def __str__(self):
return "hello mock drop"
Expand All @@ -48,9 +47,7 @@ def __init__(self, val):
self.val = val

def __eq__(self, other):
if isinstance(other, NoLiquidDrop) and self.val == other.val:
return True
return False
return bool(isinstance(other, NoLiquidDrop) and self.val == other.val)

def __str__(self):
return "hello no liquid drop"
Expand All @@ -63,9 +60,7 @@ def __init__(self, val):
def __eq__(self, other):
if isinstance(other, bool) and self.val == other:
return True
if isinstance(other, FalsyDrop) and self.val == other.val:
return True
return False
return bool(isinstance(other, FalsyDrop) and self.val == other.val)

def __str__(self):
return "falsy drop"
Expand Down

0 comments on commit 9c2ddf0

Please sign in to comment.