Add flake8-sfs

This commit is contained in:
Alexander Hess 2026-11-28 03:34:40 +01:00
commit cb8f919b1f
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
18 changed files with 44 additions and 60 deletions

View file

@ -33,17 +33,14 @@ def include_object(obj, _name, type_, _reflected, _compare_to):
engine = sa.create_engine(velofy_config.DATABASE_URI)
test_schema = f"_{velofy_config.CLEAN_SCHEMA}" if os.getenv("TESTING") else ""
with engine.connect() as connection:
context.configure(
connection=connection,
include_object=include_object,
target_metadata=db.Base.metadata,
version_table="{alembic_table}{test_schema}".format(
alembic_table=velofy_config.ALEMBIC_TABLE,
test_schema=(
f"_{velofy_config.CLEAN_SCHEMA}" if os.getenv("TESTING") else ""
),
),
version_table=f"{velofy_config.ALEMBIC_TABLE}{test_schema}",
version_table_schema=velofy_config.ALEMBIC_TABLE_SCHEMA,
)

View file

@ -299,7 +299,7 @@ def upgrade():
*(
sa.CheckConstraint(
constraint,
name="ordered_timestamps_{index}".format(index=index),
name=f"ordered_timestamps_{index}",
)
for index, constraint in enumerate(
(

View file

@ -193,6 +193,7 @@ def lint_code(session: Session) -> None:
"flake8-pyproject",
"flake8-pytest-style",
"flake8-quotes",
"flake8-sfs",
"isort",
# TODO: See comment on `mypy` below
# 'mypy',

View file

@ -102,6 +102,7 @@ dev = [
"flake8-pyproject (>=1.2.4,<2.0.0)",
"flake8-pytest-style (>=2.2.0,<3.0.0)",
"flake8-quotes (>=3.4.0,<4.0.0)",
"flake8-sfs (>=1.0.1,<2.0.0)",
"mypy (>=2.4.1,<3.0.0)",
]
@ -222,6 +223,8 @@ select = [
"BLK1", "BLK9",
# flake8-pytest-style => enforce a consistent style with pytest
"PT0",
# flake8-sfs => use f-strings as the only type of string formatting
"SFS",
]
# By default, flake8 ignores some errors.
@ -238,6 +241,8 @@ extend-ignore = [
"E203", "W503",
# Let's not do `@pytest.mark.no_cover()` instead of `@pytest.mark.no_cover`.
"PT023",
# Allow f-strings as the only type of string formatting.
"SFS301",
]
per-file-ignores = [

View file

@ -16,11 +16,9 @@ import warnings
def random_schema_name() -> str:
"""Generate a random PostgreSQL schema name for testing."""
return "temp_{name}".format(
name="".join(
(random.choice(string.ascii_lowercase) for _ in range(10)), # noqa:S311
),
)
letters = (random.choice(string.ascii_lowercase) for _ in range(10)) # noqa:S311
name = "".join(letters)
return f"temp_{name}"
class Config:

View file

@ -82,11 +82,7 @@ class Address(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}({street} in {city})>".format(
cls=self.__class__.__name__,
street=self.street,
city=self.city_name,
)
return f"<{self.__class__.__name__}({self.street} in {self.city_name})>"
@hybrid.hybrid_property
def is_primary(self) -> bool:

View file

@ -48,7 +48,7 @@ class City(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}({name})>".format(cls=self.__class__.__name__, name=self.name)
return f"<{self.__class__.__name__}({self.name})>"
@functools.cached_property
def center(self) -> utils.Location:

View file

@ -47,7 +47,4 @@ class Courier(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}(#{courier_id})>".format(
cls=self.__class__.__name__,
courier_id=self.id,
)
return f"<{self.__class__.__name__}(#{self.id})>"

View file

@ -21,10 +21,7 @@ class Customer(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}(#{customer_id})>".format(
cls=self.__class__.__name__,
customer_id=self.id,
)
return f"<{self.__class__.__name__}(#{self.id})>"
# Relationships
orders = orm.relationship("Order", back_populates="customer")

View file

@ -142,13 +142,9 @@ class Forecast(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}: {prediction} for pixel ({n_x}|{n_y}) at {start_at}>".format(
cls=self.__class__.__name__,
prediction=self.prediction,
n_x=self.pixel.n_x,
n_y=self.pixel.n_y,
start_at=self.start_at,
)
cls = self.__class__.__name__
pixel = f"({self.pixel.n_x}|{self.pixel.n_y})"
return f"<{cls}: {self.prediction} for pixel {pixel} at {self.start_at}>"
@classmethod
def from_dataframe(

View file

@ -51,10 +51,7 @@ class Grid(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}: {area} sqr. km>".format(
cls=self.__class__.__name__,
area=self.pixel_area,
)
return f"<{self.__class__.__name__}: {self.pixel_area} sqr. km>"
# Convenience properties
@property

View file

@ -266,7 +266,7 @@ class Order(meta.Base):
*(
sa.CheckConstraint(
constraint,
name="ordered_timestamps_{index}".format(index=index),
name=f"ordered_timestamps_{index}",
)
for index, constraint in enumerate(
(
@ -550,10 +550,7 @@ class Order(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}(#{order_id})>".format(
cls=self.__class__.__name__,
order_id=self.id,
)
return f"<{self.__class__.__name__}(#{self.id})>"
def draw(self) -> folium.Map: # pragma: no cover
"""Draw the `.waypoints` from `.pickup_address` to `.delivery_address`.

View file

@ -56,11 +56,7 @@ class Pixel(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}: ({x}|{y})>".format(
cls=self.__class__.__name__,
x=self.n_x,
y=self.n_y,
)
return f"<{self.__class__.__name__}: ({self.n_x}|{self.n_y})>"
# Convenience properties

View file

@ -266,7 +266,7 @@ class ReplayedOrder(meta.Base):
# and the non-simulated columns removed.
sa.CheckConstraint(
constraint,
name="ordered_timestamps_{index}".format(index=index),
name=f"ordered_timestamps_{index}",
)
for index, constraint in enumerate(
(
@ -338,10 +338,7 @@ class ReplayedOrder(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}(#{order_id})>".format(
cls=self.__class__.__name__,
order_id=self.actual.id,
)
return f"<{self.__class__.__name__}(#{self.actual.id})>"
# Convenience properties

View file

@ -40,9 +40,5 @@ class ReplaySimulation(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}({strategy} #{run} in {city})>".format(
cls=self.__class__.__name__,
strategy=self.strategy,
run=self.run,
city=self.city.name,
)
cls = self.__class__.__name__
return f"<{cls}({self.strategy} #{self.run} in {self.city.name})>"

View file

@ -58,7 +58,7 @@ class Restaurant(meta.Base):
def __repr__(self) -> str:
"""Non-literal text representation."""
return "<{cls}({name})>".format(cls=self.__class__.__name__, name=self.name)
return f"<{self.__class__.__name__}({self.name})>"
def clear_map(self) -> Restaurant: # pragma: no cover
"""Shortcut to the `.address.city.clear_map()` method.

View file

@ -105,7 +105,7 @@ def stl( # noqa:C901
if nt % 2 == 0 or nt < default_nt:
raise ValueError(
"`nt` must be odd and `>= (1.5 * frequency) / [1 - (1.5 / ns)]`, "
+ "which is {0}".format(default_nt),
+ f"which is {default_nt}",
)
else:
nt = default_nt

14
uv.lock generated
View file

@ -1030,6 +1030,18 @@ dependencies = [
]
sdist = { url = "https://files.pythonhosted.org/packages/dd/57/a173e3eb86072b7ee77650aca496b15d6886367d257f58ea9de5276e330a/flake8-quotes-3.4.0.tar.gz", hash = "sha256:aad8492fb710a2d3eabe68c5f86a1428de650c8484127e14c43d0504ba30276c", size = 14107, upload-time = "2024-02-10T21:58:22.357Z" }
[[package]]
name = "flake8-sfs"
version = "1.0.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "flake8" },
]
sdist = { url = "https://files.pythonhosted.org/packages/10/d0/f382713010bb429934fd03b9b0cc8726ef620719fec49c942e8fc41454e7/flake8_sfs-1.0.1.tar.gz", hash = "sha256:0cab211f805efe2b29a8480fda0d46a8cedba1d45b4dd71b9bd0675804097149", size = 6531, upload-time = "2025-09-21T09:31:42.454Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/d1/a8/dc3b3dbe52808d3f09504950d20963a3e19ab1bf6492790b70b8b2e32565/flake8_sfs-1.0.1-py3-none-any.whl", hash = "sha256:ef5f6b3e6d958894fe4c953ecf8e6156d9ab620c7e138f68af5c0f9bfdb4f6b4", size = 6651, upload-time = "2025-09-21T09:31:41.166Z" },
]
[[package]]
name = "folium"
version = "1.0.0"
@ -3680,6 +3692,7 @@ dev = [
{ name = "flake8-pyproject" },
{ name = "flake8-pytest-style" },
{ name = "flake8-quotes" },
{ name = "flake8-sfs" },
{ name = "isort" },
{ name = "mypy" },
{ name = "nox" },
@ -3739,6 +3752,7 @@ dev = [
{ name = "flake8-pyproject", specifier = ">=1.2.4,<2.0.0" },
{ name = "flake8-pytest-style", specifier = ">=2.2.0,<3.0.0" },
{ name = "flake8-quotes", specifier = ">=3.4.0,<4.0.0" },
{ name = "flake8-sfs", specifier = ">=1.0.1,<2.0.0" },
{ name = "isort", specifier = ">=9.0.2,<10.0.0" },
{ name = "mypy", specifier = ">=2.4.1,<3.0.0" },
{ name = "nox", specifier = ">=2026.10.20" },