From df68c96dee6df486b7fa5a2318b90f18742b3b72 Mon Sep 17 00:00:00 2001 From: Leif Warland Date: Thu, 9 Jan 2025 09:37:56 +0100 Subject: [PATCH] refactor: use all ruff rules --- .pre-commit-config.yaml | 2 +- pyproject.toml | 59 +++++------------------------------------ src/cimsparql/model.py | 8 +++--- 3 files changed, 13 insertions(+), 56 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 700a982d..99a96ddc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.4 + rev: v0.8.6 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/pyproject.toml b/pyproject.toml index e7b049b2..fd08eaba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,60 +39,11 @@ target-version = "py311" line-length = 120 [tool.ruff.lint] -select = [ - "A", # flake8-builtins - "ANN", # flake8-annotations - "ARG", # flake8-unused-arguments - "B", # flake8-bugbear - "C4", # flake8-comprehensions - "C90", # mccabe - "COM", # flake8-commas - "D", # pydocstyle - "DTZ", # flake8-datetimez - "E", "W", # pycodestyle - "ERA", # eradicate - "F", # Pyflakes - "FA", - "FBT", # boolean trap - "FIX", # fix me - "FLY", # flynt - "FURB", # refurb - "G", # flake8-logging-format - "I", # isort - "ICN", # import conventions - "INP", # no pep420 - "INT", # gettext - "ISC", # implicit str concat - "LOG", # flake8-logging - "N", # pep8-nameing - "NPY", # numpy specific rules - "PD", # pandas vet - "PERF", # Perflint - "PGH", - "PIE", # flake8-pie - "PL", # pylint - "PT", # pytest style - "PTH", # Pathlib - "Q", # quotes - "RET", # Return - "RSE", # raise - "RUF", # Ruff specific rules - "S", # flake8-bandit - "SIM", # flake8-simplify - "SLF", # Self - "SLOT", - "T10", # debug statements - "T20", # flake8-print - "TC", # Type checking - "TCH", # flake8-type-checking - "TID", # tidy import - "TRY", # tryceratops - "UP", # pyupgrade - "YTT", # flake8-2020 -] +select = ["ALL"] ignore = [ 'ANN401', + 'BLE001', 'COM812', 'D101', 'D102', @@ -102,15 +53,19 @@ ignore = [ 'D203', 'D213', 'D413', + 'EM101', + 'EM102', 'FBT001', 'FBT002', 'FIX002', 'S101', + 'TD002', + 'TD003', 'TRY003' ] # Allow autofix for all enabled rules (when `--fix`) is provided. -fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"] +fixable = ["ALL"] unfixable = [] # Exclude a variety of commonly ignored directories. diff --git a/src/cimsparql/model.py b/src/cimsparql/model.py index 28d506cf..e9092c30 100644 --- a/src/cimsparql/model.py +++ b/src/cimsparql/model.py @@ -9,7 +9,7 @@ from collections import defaultdict from dataclasses import dataclass, field from functools import cached_property -from typing import TYPE_CHECKING, ParamSpec, TypeVar +from typing import TYPE_CHECKING, ParamSpec, Self, TypeVar from uuid import uuid4 import pandas as pd @@ -117,13 +117,15 @@ def get_client(self, query_name: str) -> GraphDBClient: """ return self.clients[query_name] - def __enter__(self) -> Model: + def __enter__(self) -> Self: transaction_id = str(uuid4()) for client in self.clients.values(): client.add_correlation_id_to_header(transaction_id) return self - def __exit__(self, exc_type: type[BaseException], exc: BaseException, exc_tb: TracebackType) -> None: + def __exit__( + self, exc_type: type[BaseException] | None, exc: BaseException | None, exc_tb: TracebackType | None + ) -> None: _, _, _ = exc_type, exc, exc_tb for client in self.clients.values(): client.clear_correlation_id_from_header()