From 0b9f26ceeece14c6b1c7dfc9ae6501d4ec104209 Mon Sep 17 00:00:00 2001 From: Ivan Yordanov Date: Wed, 27 Sep 2023 10:36:33 +0300 Subject: [PATCH] ci(ruff-type-checking): Add "TCH001" with proper config --- kpops/component_handlers/__init__.py | 7 +++---- .../kafka_connect/kafka_connect_handler.py | 2 +- kpops/component_handlers/schema_handler/schema_handler.py | 7 +++++-- kpops/component_handlers/schema_handler/schema_provider.py | 7 ++++--- kpops/components/base_components/kafka_connector.py | 6 ++++-- kpops/pipeline_generator/pipeline.py | 7 ++++--- pyproject.toml | 5 ++++- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/kpops/component_handlers/__init__.py b/kpops/component_handlers/__init__.py index 988ca7ee7..fa296a574 100644 --- a/kpops/component_handlers/__init__.py +++ b/kpops/component_handlers/__init__.py @@ -2,11 +2,10 @@ from typing import TYPE_CHECKING -from kpops.component_handlers.kafka_connect.kafka_connect_handler import ( - KafkaConnectHandler, -) - if TYPE_CHECKING: + from kpops.component_handlers.kafka_connect.kafka_connect_handler import ( + KafkaConnectHandler, + ) from kpops.component_handlers.schema_handler.schema_handler import SchemaHandler from kpops.component_handlers.topic.handler import TopicHandler diff --git a/kpops/component_handlers/kafka_connect/kafka_connect_handler.py b/kpops/component_handlers/kafka_connect/kafka_connect_handler.py index 2c24c4d67..d4b00d6aa 100644 --- a/kpops/component_handlers/kafka_connect/kafka_connect_handler.py +++ b/kpops/component_handlers/kafka_connect/kafka_connect_handler.py @@ -8,7 +8,6 @@ ConnectorNotFoundException, ConnectorStateException, ) -from kpops.component_handlers.kafka_connect.model import KafkaConnectorConfig from kpops.component_handlers.kafka_connect.timeout import timeout from kpops.utils.colorify import magentaify from kpops.utils.dict_differ import render_diff @@ -20,6 +19,7 @@ from typing_extensions import Self from kpops.cli.pipeline_config import PipelineConfig + from kpops.component_handlers.kafka_connect.model import KafkaConnectorConfig log = logging.getLogger("KafkaConnectHandler") diff --git a/kpops/component_handlers/schema_handler/schema_handler.py b/kpops/component_handlers/schema_handler/schema_handler.py index b402c6024..1a05ec86c 100644 --- a/kpops/component_handlers/schema_handler/schema_handler.py +++ b/kpops/component_handlers/schema_handler/schema_handler.py @@ -3,22 +3,25 @@ import json import logging from functools import cached_property +from typing import TYPE_CHECKING from schema_registry.client import SchemaRegistryClient from schema_registry.client.schema import AvroSchema from kpops.cli.exception import ClassNotFoundError -from kpops.cli.pipeline_config import PipelineConfig from kpops.cli.registry import find_class from kpops.component_handlers.schema_handler.schema_provider import ( Schema, SchemaProvider, ) -from kpops.components.base_components.models.to_section import ToSection from kpops.utils.colorify import greenify, magentaify log = logging.getLogger("SchemaHandler") +if TYPE_CHECKING: + from kpops.cli.pipeline_config import PipelineConfig + from kpops.components.base_components.models.to_section import ToSection + class SchemaHandler: def __init__(self, url: str, components_module: str | None): diff --git a/kpops/component_handlers/schema_handler/schema_provider.py b/kpops/component_handlers/schema_handler/schema_provider.py index 78f653270..253491e9b 100644 --- a/kpops/component_handlers/schema_handler/schema_provider.py +++ b/kpops/component_handlers/schema_handler/schema_provider.py @@ -1,14 +1,15 @@ from __future__ import annotations from abc import ABC, abstractmethod -from typing import TypeAlias +from typing import TYPE_CHECKING, TypeAlias from schema_registry.client.schema import AvroSchema, JsonSchema -from kpops.components.base_components.models import ModelName, ModelVersion - Schema: TypeAlias = AvroSchema | JsonSchema +if TYPE_CHECKING: + from kpops.components.base_components.models import ModelName, ModelVersion + class SchemaProvider(ABC): @abstractmethod diff --git a/kpops/components/base_components/kafka_connector.py b/kpops/components/base_components/kafka_connector.py index a69bf3ab1..6420662a3 100644 --- a/kpops/components/base_components/kafka_connector.py +++ b/kpops/components/base_components/kafka_connector.py @@ -3,7 +3,7 @@ import logging from abc import ABC from functools import cached_property -from typing import Any, NoReturn +from typing import TYPE_CHECKING, Any, NoReturn from pydantic import Field, validator from typing_extensions import override @@ -25,11 +25,13 @@ KafkaConnectResetterValues, ) from kpops.components.base_components.base_defaults_component import deduplicate -from kpops.components.base_components.models.from_section import FromTopic from kpops.components.base_components.pipeline_component import PipelineComponent from kpops.utils.colorify import magentaify from kpops.utils.docstring import describe_attr +if TYPE_CHECKING: + from kpops.components.base_components.models.from_section import FromTopic + log = logging.getLogger("KafkaConnector") diff --git a/kpops/pipeline_generator/pipeline.py b/kpops/pipeline_generator/pipeline.py index fc2839082..96588beee 100644 --- a/kpops/pipeline_generator/pipeline.py +++ b/kpops/pipeline_generator/pipeline.py @@ -11,9 +11,6 @@ from rich.console import Console from rich.syntax import Syntax -from kpops.cli.pipeline_config import PipelineConfig -from kpops.cli.registry import Registry -from kpops.component_handlers import ComponentHandlers from kpops.components.base_components.pipeline_component import PipelineComponent from kpops.utils.dict_ops import generate_substitution, update_nested_pair from kpops.utils.environment import ENV @@ -23,6 +20,10 @@ from collections.abc import Iterator from pathlib import Path + from kpops.cli.pipeline_config import PipelineConfig + from kpops.cli.registry import Registry + from kpops.component_handlers import ComponentHandlers + log = logging.getLogger("PipelineGenerator") diff --git a/pyproject.toml b/pyproject.toml index 7563a267a..9855498b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,7 +99,7 @@ ignore = [ "RET506", # Unnecessary {branch} after raise statement -- Lots of false positives "RET507", # Unnecessary {branch} after continue statement -- Lots of false positives "RET508", # Unnecessary {branch} after break statement -- Lots of false positives - "TCH001", # Move application import {} into a type-checking block -- Breaks KPOps + # "TCH001", # Move application import {} into a type-checking block -- Breaks KPOps "PLR09", # upper bound on number of arguments, functions, etc. -- Inconvenient to enforce "PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable -- Inconvenient to enforce "PLW2901", # `for` loop variable `{var}` overwritten by assignment target -- Inconvenient to enforce @@ -155,6 +155,9 @@ exclude = ["tests/*snapshots/*"] [tool.ruff.flake8-bugbear] extend-immutable-calls = ["typer.Argument"] +[tool.ruff.flake8-type-checking] +runtime-evaluated-base-classes = ["pydantic.BaseModel", "kpops.components.base_components.kafka_app.KafkaApp"] + [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api"