Skip to content

Ruff target-version can be automatically inferred if requires-python is set #201

@burgholzer

Description

@burgholzer

According to https://beta.ruff.rs/docs/settings/#target-version, the target-version property used for ruff can be inferred from the project.requires-python field, if it is present.
Repo-review currently requires the target-version to be set in

class RF002(Ruff):
"Target version must be set"
requires = {"RF001"}
@staticmethod
def check(pyproject: dict[str, Any]) -> bool:
"""
Must select a minimum version to target. Affects pyupgrade,
isort, and others.
"""
match pyproject:
case {"tool": {"ruff": {"target-version": str()}}}:
return True
case _:
return False

Based on the above, this check could be relaxed a little. Maybe to something like:

class RF002(Ruff):
    "Target version must be set"
    requires = {"RF001"}

    @staticmethod
    def check(pyproject: dict[str, Any]) -> bool:
        """
        Must select a minimum version to target. Affects pyupgrade,
        isort, and others. Can be inferred from project.requires-python.
        """

        match pyproject:
            case {"tool": {"ruff": {"target-version": str()}}}:
                return True
            case {"project": {"requires-python": str()}}:
                return True
            case _:
                return False

Or even something where it is suggested to not specify tool.ruff.target-version whenever project.requires-python is specified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions