From 9918a13f732ea9f29b99ac193569c0be6f284506 Mon Sep 17 00:00:00 2001 From: mohamed-elkholy95 Date: Thu, 28 May 2026 18:35:55 -0400 Subject: [PATCH] fix(lint): migrate str+Enum to StrEnum; use PEP 695 type params (UP042, UP047) Replace class Foo(str, Enum) with class Foo(StrEnum) across pythinker-review (9 enums in cli/_shared, cli/review, engine/diff_source, store/models). Replace TypeVar T with PEP 695 type-parameter syntax in the ralph-loop test. All targets are Python 3.12+, so both StrEnum and PEP 695 are fully supported. Unblocks the ruff 0.15 Dependabot bump (PR #4). --- .../src/pythinker_review/cli/_shared.py | 6 +++--- .../src/pythinker_review/cli/review.py | 10 +++++----- .../src/pythinker_review/engine/diff_source.py | 4 ++-- .../src/pythinker_review/store/models.py | 6 +++--- tests/core/test_pythinkersoul_ralph_loop.py | 5 ++--- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/pythinker-review/src/pythinker_review/cli/_shared.py b/packages/pythinker-review/src/pythinker_review/cli/_shared.py index ebb406de..32f7bc34 100644 --- a/packages/pythinker-review/src/pythinker_review/cli/_shared.py +++ b/packages/pythinker-review/src/pythinker_review/cli/_shared.py @@ -2,18 +2,18 @@ from __future__ import annotations -from enum import Enum +from enum import StrEnum from pythinker_review.store.models import SEVERITY_ORDER, Finding, RunMeta, Severity -class OutputFormat(str, Enum): +class OutputFormat(StrEnum): pretty = "pretty" json = "json" sarif = "sarif" -class FailOn(str, Enum): +class FailOn(StrEnum): critical = "critical" high = "high" medium = "medium" diff --git a/packages/pythinker-review/src/pythinker_review/cli/review.py b/packages/pythinker-review/src/pythinker_review/cli/review.py index ad16685f..a4bc1b72 100644 --- a/packages/pythinker-review/src/pythinker_review/cli/review.py +++ b/packages/pythinker-review/src/pythinker_review/cli/review.py @@ -11,7 +11,7 @@ import sys import tomllib from collections.abc import Callable, Sequence -from enum import Enum +from enum import StrEnum from pathlib import Path from typing import Any, NoReturn @@ -82,22 +82,22 @@ app = typer.Typer(add_completion=False, no_args_is_help=True) -class ReviewMode(str, Enum): +class ReviewMode(StrEnum): default = "default" deslopify = "deslopify" -class ArtifactFormat(str, Enum): +class ArtifactFormat(StrEnum): pretty = "pretty" json = "json" -class DiffSide(str, Enum): +class DiffSide(StrEnum): right = "RIGHT" left = "LEFT" -class SimilarIssuesBackend(str, Enum): +class SimilarIssuesBackend(StrEnum): chroma = "chroma" lexical = "lexical" auto = "auto" diff --git a/packages/pythinker-review/src/pythinker_review/engine/diff_source.py b/packages/pythinker-review/src/pythinker_review/engine/diff_source.py index b7b884c1..a4b36a0c 100644 --- a/packages/pythinker-review/src/pythinker_review/engine/diff_source.py +++ b/packages/pythinker-review/src/pythinker_review/engine/diff_source.py @@ -4,13 +4,13 @@ import subprocess from dataclasses import dataclass, field -from enum import Enum +from enum import StrEnum from pathlib import Path _GIT_TIMEOUT_S = 20.0 -class DiffMode(str, Enum): +class DiffMode(StrEnum): base = "base" staged = "staged" working_tree = "working_tree" diff --git a/packages/pythinker-review/src/pythinker_review/store/models.py b/packages/pythinker-review/src/pythinker_review/store/models.py index 95e046e2..92a5b05f 100644 --- a/packages/pythinker-review/src/pythinker_review/store/models.py +++ b/packages/pythinker-review/src/pythinker_review/store/models.py @@ -3,13 +3,13 @@ from __future__ import annotations from datetime import datetime -from enum import Enum +from enum import StrEnum from typing import Literal, Self from pydantic import BaseModel, ConfigDict, Field, model_validator -class Severity(str, Enum): +class Severity(StrEnum): critical = "critical" high = "high" medium = "medium" @@ -26,7 +26,7 @@ class Severity(str, Enum): } -class Category(str, Enum): +class Category(StrEnum): correctness = "correctness" security = "security" debugging = "debugging" diff --git a/tests/core/test_pythinkersoul_ralph_loop.py b/tests/core/test_pythinkersoul_ralph_loop.py index f60d9b33..97cb0695 100644 --- a/tests/core/test_pythinkersoul_ralph_loop.py +++ b/tests/core/test_pythinkersoul_ralph_loop.py @@ -3,7 +3,7 @@ import asyncio from collections.abc import AsyncIterator, Sequence from pathlib import Path -from typing import Self, TypeVar +from typing import Self import pytest from inline_snapshot import Snapshot, snapshot @@ -31,7 +31,6 @@ def approval() -> Approval: return Approval(yolo=False) -T = TypeVar("T") RALPH_IMAGE_URL = "https://example.com/test.png" RALPH_IMAGE_USER_INPUT = [ TextPart(text="Check this image"), @@ -39,7 +38,7 @@ def approval() -> Approval: ] -def expect_snapshot(value: T, expected: Snapshot[T]) -> None: +def expect_snapshot[T](value: T, expected: Snapshot[T]) -> None: if expected != value: pytest.fail(f"Snapshot mismatch: {value!r} != {expected!r}")