Skip to content

Commit

Permalink
ci(linters): address ruff warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
  • Loading branch information
cmatsuoka authored and sergiusens committed Sep 6, 2023
1 parent 8dc52f0 commit 1759f8d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions craft_application/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""
from __future__ import annotations

from typing import TYPE_CHECKING, TypeVar
from typing import TYPE_CHECKING, Self, TypeVar

from craft_cli import CraftError

Expand Down Expand Up @@ -76,7 +76,7 @@ def from_pydantic(
*,
file_name: str = "yaml file",
**kwargs: str | bool | int,
) -> _ErrType:
) -> Self:
"""Convert this error from a pydantic ValidationError.
:param error: The pydantic error to convert
Expand All @@ -91,12 +91,12 @@ class PartsLifecycleError(CraftError):
"""Error during parts processing."""

@classmethod
def from_parts_error(cls: type[_ErrType], err: craft_parts.PartsError) -> _ErrType:
def from_parts_error(cls: type[_ErrType], err: craft_parts.PartsError) -> Self:
"""Shortcut to create a PartsLifecycleError from a PartsError."""
return cls(message=err.brief, details=err.details, resolution=err.resolution)

@classmethod
def from_os_error(cls: type[_ErrType], err: OSError) -> _ErrType:
def from_os_error(cls: type[_ErrType], err: OSError) -> Self:
"""Create a PartsLifecycleError from an OSError."""
message = f"{err.filename}: {err.strerror}" if err.filename else err.strerror
details = err.__class__.__name__
Expand Down
6 changes: 3 additions & 3 deletions craft_application/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""Base pydantic model for *craft applications."""
from __future__ import annotations

from typing import TYPE_CHECKING, Any, TypeVar
from typing import TYPE_CHECKING, Any, Self, TypeVar

import pydantic
import yaml
Expand Down Expand Up @@ -54,7 +54,7 @@ def marshal(self) -> dict[str, str | list[str] | dict[str, Any]]:
return self.dict(by_alias=True, exclude_unset=True)

@classmethod
def unmarshal(cls: type[_ModelType], data: dict[str, Any] | Any) -> _ModelType:
def unmarshal(cls: type[_ModelType], data: dict[str, Any]) -> Self:
"""Create and populate a new model object from dictionary data.
The unmarshal method validates entries in the input dictionary, populating
Expand All @@ -69,7 +69,7 @@ def unmarshal(cls: type[_ModelType], data: dict[str, Any] | Any) -> _ModelType:
return cls(**data)

@classmethod
def from_yaml_file(cls: type[_ModelType], path: pathlib.Path) -> _ModelType:
def from_yaml_file(cls: type[_ModelType], path: pathlib.Path) -> Self:
"""Instantiate this model from a YAML file."""
with path.open() as file:
data = safe_yaml_load(file)
Expand Down
3 changes: 1 addition & 2 deletions craft_application/util/error_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ def _format_pydantic_error_location(loc: Iterable[Union[str, int]]) -> str:
loc = ".".join(loc_parts)

# Filter out internal __root__ detail.
loc = loc.replace(".__root__", "")
return loc
return loc.replace(".__root__", "")


def _format_pydantic_error_message(msg: str) -> str:
Expand Down

0 comments on commit 1759f8d

Please sign in to comment.