PLC0415: fix
This commit is contained in:
@@ -20,6 +20,7 @@ from clan_lib.async_run import get_current_thread_opkey
|
||||
from clan_lib.errors import ClanError
|
||||
|
||||
from .serde import dataclass_to_dict, from_dict, sanitize_string
|
||||
from .type_to_jsonschema import JSchemaTypeError, type_to_dict
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -201,10 +202,6 @@ API.register(get_system_file)
|
||||
return fn
|
||||
|
||||
def to_json_schema(self) -> dict[str, Any]:
|
||||
from typing import get_type_hints
|
||||
|
||||
from .type_to_jsonschema import JSchemaTypeError, type_to_dict
|
||||
|
||||
api_schema: dict[str, Any] = {
|
||||
"$comment": "An object containing API methods. ",
|
||||
"type": "object",
|
||||
@@ -268,8 +265,6 @@ API.register(get_system_file)
|
||||
return api_schema
|
||||
|
||||
def get_method_argtype(self, method_name: str, arg_name: str) -> Any:
|
||||
from inspect import signature
|
||||
|
||||
func = self._registry.get(method_name, None)
|
||||
if not func:
|
||||
msg = f"API Method {method_name} not found in registry. Available methods: {list(self._registry.keys())}"
|
||||
@@ -313,9 +308,9 @@ def load_in_all_api_functions() -> None:
|
||||
We have to make sure python loads every wrapped function at least once.
|
||||
This is done by importing all modules from the clan_lib and clan_cli packages.
|
||||
"""
|
||||
import clan_cli
|
||||
import clan_cli # noqa: PLC0415 # Avoid circular imports - many modules import from clan_lib.api
|
||||
|
||||
import clan_lib
|
||||
import clan_lib # noqa: PLC0415 # Avoid circular imports - many modules import from clan_lib.api
|
||||
|
||||
import_all_modules_from_package(clan_lib)
|
||||
import_all_modules_from_package(clan_cli)
|
||||
|
||||
@@ -4,8 +4,7 @@ from pathlib import Path
|
||||
from typing import Any, Literal
|
||||
|
||||
from clan_lib.cmd import RunOpts, run
|
||||
from clan_lib.flake import Flake
|
||||
from clan_lib.nix import nix_shell
|
||||
from clan_lib.flake.flake import Flake
|
||||
|
||||
from . import API
|
||||
|
||||
@@ -89,6 +88,8 @@ def list_system_storage_devices() -> Blockdevices:
|
||||
A list of detected block devices with metadata like size, path, type, etc.
|
||||
|
||||
"""
|
||||
from clan_lib.nix import nix_shell # noqa: PLC0415
|
||||
|
||||
cmd = nix_shell(
|
||||
["util-linux"],
|
||||
[
|
||||
@@ -123,7 +124,7 @@ def get_clan_directory_relative(flake: Flake) -> str:
|
||||
ClanError: If the flake evaluation fails or directories cannot be found
|
||||
|
||||
"""
|
||||
from clan_lib.dirs import get_clan_directories
|
||||
from clan_lib.dirs import get_clan_directories # noqa: PLC0415
|
||||
|
||||
_, relative_dir = get_clan_directories(flake)
|
||||
return relative_dir
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Any, Literal, TypedDict
|
||||
|
||||
@@ -334,8 +335,6 @@ def test_literal_field() -> None:
|
||||
|
||||
|
||||
def test_enum_roundtrip() -> None:
|
||||
from enum import Enum
|
||||
|
||||
class MyEnum(Enum):
|
||||
FOO = "abc"
|
||||
BAR = 2
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
|
||||
# Functions to test
|
||||
from clan_lib.api import (
|
||||
@@ -124,8 +125,6 @@ def test_filters_null_fields() -> None:
|
||||
|
||||
|
||||
def test_custom_enum() -> None:
|
||||
from enum import Enum
|
||||
|
||||
class CustomEnum(Enum):
|
||||
FOO = "foo"
|
||||
BAR = "bar"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, NotRequired, Required
|
||||
from enum import Enum
|
||||
from typing import Any, Generic, NotRequired, Required, TypedDict, TypeVar
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -27,8 +28,6 @@ def test_simple_primitives() -> None:
|
||||
|
||||
|
||||
def test_enum_type() -> None:
|
||||
from enum import Enum
|
||||
|
||||
class Color(Enum):
|
||||
RED = "red"
|
||||
GREEN = "green"
|
||||
@@ -224,8 +223,6 @@ def test_nested_open_dicts() -> None:
|
||||
|
||||
|
||||
def test_type_variables() -> None:
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
@dataclass
|
||||
@@ -254,8 +251,6 @@ def test_type_variables() -> None:
|
||||
def test_type_variable_nested_scopes() -> None:
|
||||
# Define two type variables with the same name "T" but in different scopes
|
||||
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
@dataclass
|
||||
@@ -284,8 +279,6 @@ def test_type_variable_nested_scopes() -> None:
|
||||
|
||||
|
||||
def test_total_typed_dict() -> None:
|
||||
from typing import TypedDict
|
||||
|
||||
class ExampleTypedDict(TypedDict):
|
||||
name: str
|
||||
value: NotRequired[int]
|
||||
@@ -314,8 +307,6 @@ def test_total_typed_dict() -> None:
|
||||
|
||||
|
||||
def test_open_typed_dict() -> None:
|
||||
from typing import TypedDict
|
||||
|
||||
class ExampleTypedDict(TypedDict, total=False):
|
||||
name: Required[str]
|
||||
value: int
|
||||
|
||||
Reference in New Issue
Block a user