Skip to content

Commit

Permalink
chore: use more of ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Feb 5, 2025
1 parent 3adef4d commit a0a1ab7
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 158 deletions.
41 changes: 7 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,42 +132,15 @@ ignore = [
"TRY003", # WONTFIX: Avoid specifying long messages outside the exception class
"PLR0913", # WONTFIX: Too many arguments to function call
"PLR2004", # TODO: Magic value used in comparison, consider replacing 201 with a constant variable
"COM", # CONFIG: No trailing commas
"PT", # CONFIG: Not using pytest
"PTH", # TODO: Not using pathlib
"EM", # TODO: Exception strings
"FBT", # TODO: Boolean in function definition
"ANN", # TODO: type annotations
"N818" # TODO: exception naming
]
select = [
"E",
"F",
"B",
"T10",
"A",
"C4",
"C90",
"YTT",
"DJ",
"UP",
"D",
"PD",
"PGH",
"PL",
"TRY",
"RUF",
"ERA",
"ICN",
"ISC",
"EXE",
"INP",
"PIE",
"G",
"PYI",
"Q",
"SIM",
"TID",
"RSE",
"T20",
"RET",
"SLF",
"N"
]
select = ["ALL"]

[tool.ruff.lint.mccabe]
max-complexity = 16
Expand Down
7 changes: 4 additions & 3 deletions wlc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""Weblate API client library."""

from __future__ import annotations

import json
import logging
from copy import copy
Expand Down Expand Up @@ -153,7 +154,7 @@ def process_error(self, error):
reason = error.response.reason
try:
error_string = str(error.response.json())
except Exception:
except Exception: # noqa: BLE001
error_string = ""
raise WeblateException(
f"HTTP error {status_code}: {reason} {error_string}"
Expand Down Expand Up @@ -221,7 +222,7 @@ def post(self, path, files=None, params=None, **kwargs):

def _post_factory(self, prefix, path, kwargs):
"""Wrapper for posting objects."""
return self.post("/".join((prefix, path, "")), **kwargs)
return self.post(f"{prefix}/{path}/", **kwargs)

def get(self, path, params=None):
"""Perform GET request on the API."""
Expand All @@ -238,7 +239,7 @@ def list_factory(self, path, parser, params=None):

def _get_factory(self, prefix, path, parser):
"""Wrapper for getting objects."""
data = self.get("/".join((prefix, path, "")))
data = self.get(f"{prefix}/{path}/")
return parser(weblate=self, **data)

def get_object(self, path):
Expand Down
5 changes: 4 additions & 1 deletion wlc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

import os.path
from configparser import NoOptionError, RawConfigParser
from collections.abc import Generator
from typing import TYPE_CHECKING

from xdg.BaseDirectory import load_config_paths # type: ignore[import-untyped]

import wlc

if TYPE_CHECKING:
from collections.abc import Generator

__all__ = ["NoOptionError", "WeblateConfig"]


Expand Down
3 changes: 2 additions & 1 deletion wlc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""Command-line interface for Weblate."""

from __future__ import annotations

import csv
import http.client
import json
Expand Down Expand Up @@ -81,7 +82,7 @@ class CommandError(Exception):
def __init__(self, message, detail=None):
"""Create CommandError exception."""
if detail is not None:
message = "\n".join((message, detail))
message = f"{message}\n{detail}"
super().__init__(message)


Expand Down
5 changes: 3 additions & 2 deletions wlc/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""Test helpers."""

from __future__ import annotations

import os
from email import message_from_string
from hashlib import blake2b
Expand Down Expand Up @@ -112,7 +113,7 @@ def format_multipart_body(body, content_type):
def register_uri(path, domain="http://127.0.0.1:8000/api", auth=False):
"""Simplified URL registration."""
filename = os.path.join(DATA_TEST_BASE, path.replace("/", "-"))
url = "/".join((domain, path, ""))
url = f"{domain}/{path}/"
with open(filename, "rb") as handle:
responses.add_callback(
responses.GET,
Expand Down Expand Up @@ -157,7 +158,7 @@ def register_error(
path, code, domain="http://127.0.0.1:8000/api", method=responses.GET, **kwargs
):
"""Simplified URL error registration."""
url = "/".join((domain, path, ""))
url = f"{domain}/{path}/"
if "callback" in kwargs:
responses.add_callback(method, url, **kwargs)
else:
Expand Down
Loading

0 comments on commit a0a1ab7

Please sign in to comment.