From e5d5c518af53b159ec6f1678bdfb88171170425a Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Thu, 26 Jan 2023 13:01:28 +0100 Subject: [PATCH] Remove class var --- .../base_components/base_defaults_component.py | 4 ++-- kpops/components/base_components/kafka_app.py | 4 ++-- kpops/components/base_components/kafka_connect.py | 8 ++++---- kpops/components/base_components/kubernetes_app.py | 4 ++-- .../streams_bootstrap/producer/producer_app.py | 4 ++-- .../streams_bootstrap/streams/streams_app.py | 4 ++-- tests/cli/test_registry.py | 6 +++--- tests/components/test_base_defaults_component.py | 10 +++++----- tests/components/test_streams_app.py | 4 ++-- tests/pipeline/test_components/components.py | 10 +++++----- .../components.py | 8 ++++---- 11 files changed, 33 insertions(+), 33 deletions(-) diff --git a/kpops/components/base_components/base_defaults_component.py b/kpops/components/base_components/base_defaults_component.py index c47a36a52..4b0e567c4 100644 --- a/kpops/components/base_components/base_defaults_component.py +++ b/kpops/components/base_components/base_defaults_component.py @@ -4,7 +4,7 @@ from collections import deque from collections.abc import Mapping, Sequence from pathlib import Path -from typing import ClassVar, TypeVar +from typing import TypeVar import typer from pydantic import BaseConfig, BaseModel, Field, PrivateAttr @@ -17,7 +17,7 @@ class BaseDefaultsComponent(BaseModel): - type: ClassVar[str] = Field(..., const=True) # component type discriminator + type: str = Field(..., const=True) # component type discriminator enrich: bool = Field(default=False, exclude=True) config: PipelineConfig = Field(default=..., exclude=True) diff --git a/kpops/components/base_components/kafka_app.py b/kpops/components/base_components/kafka_app.py index 341cd0622..942fc8a1d 100644 --- a/kpops/components/base_components/kafka_app.py +++ b/kpops/components/base_components/kafka_app.py @@ -1,7 +1,7 @@ from __future__ import annotations import logging -from typing import ClassVar, Literal +from typing import Literal from pydantic import BaseModel, Extra from typing_extensions import override @@ -38,7 +38,7 @@ class KafkaApp(KubernetesApp): Producer or streaming apps should inherit from this class. """ - type: ClassVar[Literal["kafka-app"]] = "kafka-app" + type: Literal["kafka-app"] = "kafka-app" app: KafkaAppConfig def __init__(self, **kwargs) -> None: diff --git a/kpops/components/base_components/kafka_connect.py b/kpops/components/base_components/kafka_connect.py index 8545d0c82..edb368b64 100644 --- a/kpops/components/base_components/kafka_connect.py +++ b/kpops/components/base_components/kafka_connect.py @@ -1,7 +1,7 @@ import json import os from abc import ABC -from typing import ClassVar, Literal, NoReturn +from typing import Literal, NoReturn from typing_extensions import override @@ -14,7 +14,7 @@ class KafkaConnector(PipelineComponent, ABC): - type: ClassVar[Literal["kafka-connect"]] = "kafka-connect" + type: Literal["kafka-connect"] = "kafka-connect" app: KafkaConnectConfig def __init__(self, **kwargs) -> None: @@ -64,7 +64,7 @@ def clean(self, dry_run: bool) -> None: class KafkaSourceConnector(KafkaConnector): - type: ClassVar[Literal["kafka-source-connector"]] = "kafka-source-connector" + type: Literal["kafka-source-connector"] = "kafka-source-connector" @override def apply_from_inputs(self, name: str, topic: FromTopic) -> NoReturn: @@ -90,7 +90,7 @@ def __run_kafka_connect_resetter(self, dry_run: bool) -> None: class KafkaSinkConnector(KafkaConnector): - type: ClassVar[Literal["kafka-sink-connector"]] = "kafka-sink-connector" + type: Literal["kafka-sink-connector"] = "kafka-sink-connector" @override def add_input_topics(self, topics: list[str]) -> None: diff --git a/kpops/components/base_components/kubernetes_app.py b/kpops/components/base_components/kubernetes_app.py index 112d2edb9..8f8e0e676 100644 --- a/kpops/components/base_components/kubernetes_app.py +++ b/kpops/components/base_components/kubernetes_app.py @@ -3,7 +3,7 @@ import logging import re from functools import cached_property -from typing import ClassVar, Literal +from typing import Literal from pydantic import BaseModel from typing_extensions import override @@ -36,7 +36,7 @@ class Config(CamelCaseConfig): class KubernetesApp(PipelineComponent): """Base kubernetes app""" - type: ClassVar[Literal["kubernetes-app"]] = "kubernetes-app" + type: Literal["kubernetes-app"] = "kubernetes-app" app: KubernetesAppConfig version: str | None = None diff --git a/kpops/components/streams_bootstrap/producer/producer_app.py b/kpops/components/streams_bootstrap/producer/producer_app.py index ee72d1801..ded790012 100644 --- a/kpops/components/streams_bootstrap/producer/producer_app.py +++ b/kpops/components/streams_bootstrap/producer/producer_app.py @@ -1,4 +1,4 @@ -from typing import ClassVar, Literal +from typing import Literal from pydantic import BaseConfig, Extra from typing_extensions import override @@ -20,7 +20,7 @@ class ProducerApp(KafkaApp): This producer holds configuration to use as values for the streams bootstrap produce helm chart. """ - type: ClassVar[Literal["producer"]] = "producer" + type: Literal["producer"] = "producer" app: ProducerValues class Config(BaseConfig): diff --git a/kpops/components/streams_bootstrap/streams/streams_app.py b/kpops/components/streams_bootstrap/streams/streams_app.py index cd631161e..56a64353a 100644 --- a/kpops/components/streams_bootstrap/streams/streams_app.py +++ b/kpops/components/streams_bootstrap/streams/streams_app.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import ClassVar, Literal +from typing import Literal from pydantic import BaseConfig, Extra from typing_extensions import override @@ -16,7 +16,7 @@ class StreamsApp(KafkaApp): StreamsApp component that configures a streams bootstrap app """ - type: ClassVar[Literal["streams-app"]] = "streams-app" + type: Literal["streams-app"] = "streams-app" app: StreamsAppConfig class Config(BaseConfig): diff --git a/tests/cli/test_registry.py b/tests/cli/test_registry.py index 619613b77..f1058df8a 100644 --- a/tests/cli/test_registry.py +++ b/tests/cli/test_registry.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import ClassVar, Literal +from typing import Literal import pytest from pydantic import BaseModel @@ -10,12 +10,12 @@ class SubComponent(PipelineComponent): - type: ClassVar[Literal["sub-component"]] = "sub-component" + type: Literal["sub-component"] = "sub-component" pass class SubSubComponent(SubComponent): - type: ClassVar[Literal["sub-sub-component"]] = "sub-sub-component" + type: Literal["sub-sub-component"] = "sub-sub-component" pass diff --git a/tests/components/test_base_defaults_component.py b/tests/components/test_base_defaults_component.py index 31b4d4a07..2c37f9b71 100644 --- a/tests/components/test_base_defaults_component.py +++ b/tests/components/test_base_defaults_component.py @@ -1,6 +1,6 @@ import os from pathlib import Path -from typing import ClassVar, Literal +from typing import Literal from unittest.mock import MagicMock import pytest @@ -17,7 +17,7 @@ class TestParentModel(BaseDefaultsComponent): __test__ = False - type: ClassVar[Literal["parent"]] = "parent" + type: Literal["parent"] = "parent" name: str | None = None value: float | None = None hard_coded: str = "hard_coded_value" @@ -25,14 +25,14 @@ class TestParentModel(BaseDefaultsComponent): class TestChildModel(TestParentModel): __test__ = False - type: ClassVar[Literal["child"]] = "child" + type: Literal["child"] = "child" nice: dict | None = None another_hard_coded: str = "another_hard_coded_value" class TestGrandChildModel(TestChildModel): __test__ = False - type: ClassVar[Literal["grand-child"]] = "grand-child" + type: Literal["grand-child"] = "grand-child" grand_child: str | None = None @@ -126,7 +126,7 @@ def test_env_var_substitution( self, config: PipelineConfig, handlers: ComponentHandlers ): class TestEnvVarModel(BaseDefaultsComponent): - type: ClassVar[Literal["env-var-test"]] = "env-var-test" + type: Literal["env-var-test"] = "env-var-test" name: str | None = None os.environ["pipeline_name"] = str(DEFAULTS_PATH) diff --git a/tests/components/test_streams_app.py b/tests/components/test_streams_app.py index 10e204e42..59fabe370 100644 --- a/tests/components/test_streams_app.py +++ b/tests/components/test_streams_app.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import ClassVar, Literal +from typing import Literal from unittest.mock import MagicMock import pytest @@ -72,7 +72,7 @@ def streams_app( def test_set_topics(self, config: PipelineConfig, handlers: ComponentHandlers): class AnotherType(StreamsApp): - type: ClassVar[Literal["test"]] = "test" + type: Literal["test"] = "test" streams_app = AnotherType( config=config, diff --git a/tests/pipeline/test_components/components.py b/tests/pipeline/test_components/components.py index de492ec51..b140e0805 100644 --- a/tests/pipeline/test_components/components.py +++ b/tests/pipeline/test_components/components.py @@ -1,4 +1,4 @@ -from typing import Any, ClassVar, Literal +from typing import Any, Literal from schema_registry.client.schema import AvroSchema from typing_extensions import override @@ -14,11 +14,11 @@ class ImportProducer(ProducerApp): - type: ClassVar[Literal["scheduled-producer"]] = "scheduled-producer" + type: Literal["scheduled-producer"] = "scheduled-producer" class Converter(StreamsApp): - type: ClassVar[Literal["converter"]] = "converter" + type: Literal["converter"] = "converter" class SubStreamsApp(StreamsApp): @@ -28,11 +28,11 @@ class SubStreamsApp(StreamsApp): class Filter(SubStreamsApp): """Subsubclass of StreamsApp to test inheritance.""" - type: ClassVar[Literal["filter"]] = "filter" + type: Literal["filter"] = "filter" class InflateStep(StreamsApp): - type: ClassVar[Literal["should-inflate"]] = "should-inflate" + type: Literal["should-inflate"] = "should-inflate" @override def inflate(self) -> list[PipelineComponent]: diff --git a/tests/pipeline/test_components_without_schema_handler/components.py b/tests/pipeline/test_components_without_schema_handler/components.py index cf0e13e3a..d7e217c50 100644 --- a/tests/pipeline/test_components_without_schema_handler/components.py +++ b/tests/pipeline/test_components_without_schema_handler/components.py @@ -1,4 +1,4 @@ -from typing import ClassVar, Literal +from typing import Literal from typing_extensions import override @@ -10,15 +10,15 @@ class ImportProducer(ProducerApp): - type: ClassVar[Literal["scheduled-producer"]] = "scheduled-producer" + type: Literal["scheduled-producer"] = "scheduled-producer" class Converter(StreamsApp): - type: ClassVar[Literal["converter"]] = "converter" + type: Literal["converter"] = "converter" class InflateStep(StreamsApp): - type: ClassVar[Literal["should-inflate"]] = "should-inflate" + type: Literal["should-inflate"] = "should-inflate" @override def inflate(self) -> list[PipelineComponent]: