Skip to content

fix: Support ruff 0.12 #1270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ jobs:
- name: Run mypy
run: pdm mypy --show-error-codes

- name: Lint
run: pdm run ruff check .

- name: Run unit tests only # snapshots are expected to fail
run: pdm unit_test

Expand Down
6 changes: 2 additions & 4 deletions openapi_python_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@

import typer

from openapi_python_client import MetaType
from openapi_python_client import MetaType, __version__
from openapi_python_client.config import Config, ConfigFile
from openapi_python_client.parser.errors import ErrorLevel, GeneratorError, ParseError

app = typer.Typer(name="openapi-python-client")


def _version_callback(value: bool) -> None:
from openapi_python_client import __version__

if value:
typer.echo(f"openapi-python-client version: {__version__}")
raise typer.Exit()
Expand Down Expand Up @@ -153,7 +151,7 @@ def generate(
),
) -> None:
"""Generate a new OpenAPI Client library"""
from . import generate
from . import generate # noqa: PLC0415

config = _process_config(
url=url,
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/parser/properties/any.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def build(

@classmethod
def convert_value(cls, value: Any) -> Value | None:
from .string import StringProperty
from .string import StringProperty # noqa: PLC0415

if value is None:
return value
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/parser/properties/list_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def build(
`(result, schemas)` where `schemas` is an updated version of the input named the same including any inner
classes that were defined and `result` is either the `ListProperty` or a `PropertyError`.
"""
from . import property_from_data
from . import property_from_data # noqa: PLC0415

if data.items is None and not data.prefixItems:
return (
Expand Down
6 changes: 3 additions & 3 deletions openapi_python_client/parser/properties/model_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ def _process_properties( # noqa: PLR0912, PLR0911
config: Config,
roots: set[ReferencePath | utils.ClassName],
) -> _PropertyData | PropertyError:
from . import property_from_data
from .merge_properties import merge_properties
from . import property_from_data # noqa: PLC0415
from .merge_properties import merge_properties # noqa: PLC0415

properties: dict[str, Property] = {}
relative_imports: set[str] = set()
Expand Down Expand Up @@ -353,7 +353,7 @@ def _get_additional_properties(
config: Config,
roots: set[ReferencePath | utils.ClassName],
) -> tuple[Property | None | PropertyError, Schemas]:
from . import property_from_data
from . import property_from_data # noqa: PLC0415

if schema_additional is None:
return ANY_ADDITIONAL_PROPERTY, schemas
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/parser/properties/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def to_docstring(self) -> str:
@property
def is_base_type(self) -> bool:
"""Base types, represented by any other of `Property` than `ModelProperty` should not be quoted."""
from . import ListProperty, ModelProperty, UnionProperty
from . import ListProperty, ModelProperty, UnionProperty # noqa: PLC0415

return self.__class__.__name__ not in {
ModelProperty.__name__,
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/parser/properties/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def update_schemas_with_data(
See Also:
- https://swagger.io/docs/specification/using-ref/
"""
from . import property_from_data
from . import property_from_data # noqa: PLC0415

prop: Union[PropertyError, Property]
prop, schemas = property_from_data(
Expand Down
4 changes: 2 additions & 2 deletions openapi_python_client/parser/properties/union.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def build(
`(result, schemas)` where `schemas` is the updated version of the input `schemas` and `result` is the
constructed `UnionProperty` or a `PropertyError` describing what went wrong.
"""
from . import property_from_data
from . import property_from_data # noqa: PLC0415

sub_properties: list[PropertyProtocol] = []

Expand Down Expand Up @@ -180,7 +180,7 @@ def get_lazy_imports(self, *, prefix: str) -> set[str]:

def validate_location(self, location: oai.ParameterLocation) -> ParseError | None:
"""Returns an error if this type of property is not allowed in the given location"""
from ..properties import Property
from ..properties import Property # noqa: PLC0415

for inner_prop in self.inner_properties:
if evolve(cast(Property, inner_prop), required=self.required).validate_location(location) is not None:
Expand Down
40 changes: 20 additions & 20 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies = [
"python-dateutil>=2.8.1,<3.0.0",
"httpx>=0.23.0,<0.29.0",
"ruamel.yaml>=0.18.6,<0.19.0",
"ruff>=0.2,<0.12",
"ruff>=0.2,<0.13",
"typing-extensions>=4.8.0,<5.0.0",
]
name = "openapi-python-client"
Expand Down
3 changes: 0 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def model_property_factory() -> ModelFactory:

You can pass the same params into this as the ModelProperty constructor to override defaults.
"""
from openapi_python_client.parser.properties import Class

def _factory(**kwargs):
kwargs = _common_kwargs(kwargs)
Expand Down Expand Up @@ -130,7 +129,6 @@ def enum_property_factory() -> EnumFactory[EnumProperty]:

You can pass the same params into this as the EnumProerty constructor to override defaults.
"""
from openapi_python_client.parser.properties import Class

return _simple_factory(
EnumProperty,
Expand All @@ -149,7 +147,6 @@ def literal_enum_property_factory() -> EnumFactory[LiteralEnumProperty]:

You can pass the same params into this as the LiteralEnumProerty constructor to override defaults.
"""
from openapi_python_client.parser.properties import Class

return _simple_factory(
LiteralEnumProperty,
Expand Down
6 changes: 2 additions & 4 deletions tests/test___init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import MagicMock

import pytest

from openapi_python_client import Config, ErrorLevel, Project
Expand All @@ -7,10 +9,6 @@


def make_project(config: Config) -> Project:
from unittest.mock import MagicMock

from openapi_python_client import Project

return Project(openapi=MagicMock(title="My Test API"), config=config)


Expand Down
12 changes: 2 additions & 10 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
from typer.testing import CliRunner

from openapi_python_client.cli import app

runner = CliRunner()


def test_version() -> None:
from openapi_python_client.cli import app

result = runner.invoke(app, ["--version", "generate"])

assert result.exit_code == 0
assert "openapi-python-client version: " in result.stdout


def test_bad_config() -> None:
from openapi_python_client.cli import app

config_path = "config/path"
path = "cool/path"

Expand All @@ -26,15 +24,11 @@ def test_bad_config() -> None:

class TestGenerate:
def test_generate_no_params(self) -> None:
from openapi_python_client.cli import app

result = runner.invoke(app, ["generate"])

assert result.exit_code == 1, result.output

def test_generate_url_and_path(self) -> None:
from openapi_python_client.cli import app

result = runner.invoke(app, ["generate", "--path=blah", "--url=otherblah"])

assert result.exit_code == 1
Expand All @@ -43,8 +37,6 @@ def test_generate_url_and_path(self) -> None:
def test_generate_encoding_errors(self) -> None:
path = "cool/path"
file_encoding = "error-file-encoding"
from openapi_python_client.cli import app

result = runner.invoke(app, ["generate", f"--path={path}", f"--file-encoding={file_encoding}"])

assert result.exit_code == 1
Expand Down
Loading