Skip to content

Commit

Permalink
ci(linters): address pyright 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 1759f8d commit 0d5ef51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 5 additions & 6 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, Self, TypeVar
from typing import TYPE_CHECKING

from craft_cli import CraftError

Expand All @@ -28,8 +28,7 @@
if TYPE_CHECKING: # pragma: no cover
import craft_parts
import pydantic

_ErrType = TypeVar("_ErrType", bound=CraftError)
from typing_extensions import Self


class ApplicationError(CraftError):
Expand Down Expand Up @@ -71,7 +70,7 @@ class CraftValidationError(CraftError):

@classmethod
def from_pydantic(
cls: type[_ErrType],
cls,
error: pydantic.ValidationError,
*,
file_name: str = "yaml file",
Expand All @@ -91,12 +90,12 @@ class PartsLifecycleError(CraftError):
"""Error during parts processing."""

@classmethod
def from_parts_error(cls: type[_ErrType], err: craft_parts.PartsError) -> Self:
def from_parts_error(cls, 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) -> Self:
def from_os_error(cls, 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
10 changes: 5 additions & 5 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, Self, TypeVar
from typing import TYPE_CHECKING, Any

import pydantic
import yaml
Expand All @@ -27,7 +27,7 @@
if TYPE_CHECKING: # pragma: no cover
import pathlib

_ModelType = TypeVar("_ModelType", bound="CraftBaseModel")
from typing_extensions import Self


def _alias_generator(s: str) -> str:
Expand All @@ -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]) -> Self:
def unmarshal(cls, 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 @@ -63,13 +63,13 @@ def unmarshal(cls: type[_ModelType], data: dict[str, Any]) -> Self:
:return: The newly created object.
:raise TypeError: If data is not a dictionary.
"""
if not isinstance(data, dict):
if not isinstance(data, dict): # pyright: ignore[reportUnnecessaryIsInstance]
raise TypeError("Project data is not a dictionary")

return cls(**data)

@classmethod
def from_yaml_file(cls: type[_ModelType], path: pathlib.Path) -> Self:
def from_yaml_file(cls, path: pathlib.Path) -> Self:
"""Instantiate this model from a YAML file."""
with path.open() as file:
data = safe_yaml_load(file)
Expand Down

0 comments on commit 0d5ef51

Please sign in to comment.