From 8c6e0e977c5824ef7de2c802a084ecead29ca883 Mon Sep 17 00:00:00 2001 From: Jarkko Jaakola Date: Wed, 8 Jan 2025 12:15:31 +0200 Subject: [PATCH 1/3] chore: use ruff --- .flake8 | 14 ------- .pre-commit-config.yaml | 40 +++++-------------- pyproject.toml | 4 +- src/karapace/client.py | 2 +- src/karapace/forward_client.py | 2 +- src/karapace/kafka_rest_apis/__init__.py | 6 +-- .../kafka_rest_apis/consumer_manager.py | 6 +-- src/karapace/rapu.py | 2 +- src/schema_registry/messaging.py | 2 +- src/schema_registry/reader.py | 2 +- tests/integration/test_schema_coordinator.py | 2 +- 11 files changed, 24 insertions(+), 58 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index ce13ab625..000000000 --- a/.flake8 +++ /dev/null @@ -1,14 +0,0 @@ -[flake8] -max-line-length = 125 - -# E203,W503: incompatibilities with black -# E722: also signaled by pylint (disabling here globally and on case-by-case basis with pylint) -# E501: line length -# E203: whitespace before ':' -# W503: line break before binary operator -# E722: do not use bare 'except' -ignore = - E501, - E203, - W503, - E722, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ee1505771..cfcb550bf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,36 +30,6 @@ repos: hooks: - id: shfmt -- repo: https://github.com/asottile/pyupgrade - rev: v3.4.0 - hooks: - - id: pyupgrade - args: [ --py310-plus ] - -- repo: https://github.com/pycqa/autoflake - rev: v2.1.1 - hooks: - - id: autoflake - args: - - --in-place - - --remove-all-unused-imports - - --ignore-init-module-imports - -- repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - -- repo: https://github.com/psf/black - rev: 23.3.0 - hooks: - - id: black - -- repo: https://github.com/PyCQA/flake8 - rev: 7.1.0 - hooks: - - id: flake8 - - repo: https://github.com/hadolint/hadolint rev: v2.12.0 hooks: @@ -76,3 +46,13 @@ repos: rev: v3.2.6 hooks: - id: pylint + +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.8.6 + hooks: + # Run the linter. + - id: ruff + args: [ --fix ] + # Run the formatter. + - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index 729d0e829..0edaf7e36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,6 +80,7 @@ ujson = ["ujson"] dev = [ # Developer QoL "pdbpp", + "ruff", # testing "filelock", @@ -112,6 +113,5 @@ include-package-data = true [tool.setuptools_scm] version_file = "src/karapace/version.py" -[tool.black] -target-version = ["py310", "py311"] +[tool.ruff] line-length = 125 diff --git a/src/karapace/client.py b/src/karapace/client.py index 0d4213eb1..857f6221a 100644 --- a/src/karapace/client.py +++ b/src/karapace/client.py @@ -75,7 +75,7 @@ async def close(self) -> None: try: if self._client is not None: await self._client.close() - except: # pylint: disable=bare-except + except Exception: LOG.error("Could not close client") async def get_client(self) -> ClientSession: diff --git a/src/karapace/forward_client.py b/src/karapace/forward_client.py index 239de41c4..cb331c148 100644 --- a/src/karapace/forward_client.py +++ b/src/karapace/forward_client.py @@ -91,7 +91,7 @@ async def forward_request_remote( response_type: type[BaseModelResponse] | type[SimpleTypeResponse], ) -> BaseModelResponse | SimpleTypeResponse: body = await self._forward_request_remote(request=request, primary_url=primary_url) - if response_type == int: + if response_type is int: return int(body) # type: ignore[return-value] if response_type == list[int]: return json_decode(body, assume_type=list[int]) # type: ignore[return-value] diff --git a/src/karapace/kafka_rest_apis/__init__.py b/src/karapace/kafka_rest_apis/__init__.py index ccceaa513..f2f4f485d 100644 --- a/src/karapace/kafka_rest_apis/__init__.py +++ b/src/karapace/kafka_rest_apis/__init__.py @@ -98,7 +98,7 @@ async def _idle_proxy_janitor(self) -> None: try: await self._disconnect_idle_proxy_if_any() - except: # pylint: disable=bare-except + except Exception: log.exception("Disconnecting idle proxy failure") async def _disconnect_idle_proxy_if_any(self) -> None: @@ -760,7 +760,7 @@ def init_admin_client(self, verify_connection: bool = True) -> KafkaAdminClient: **get_kafka_client_auth_parameters_from_config(self.config), ) break - except: # pylint: disable=bare-except + except Exception: if retry: log.warning("Unable to start admin client, retrying") else: @@ -1095,7 +1095,7 @@ async def serialize( if ser_format == "binary": try: return base64.b64decode(obj) - except: # pylint: disable=bare-except + except Exception: KafkaRest.r( body={ "error_code": RESTErrorCodes.HTTP_BAD_REQUEST.value, diff --git a/src/karapace/kafka_rest_apis/consumer_manager.py b/src/karapace/kafka_rest_apis/consumer_manager.py index 277a0aca1..0b26af7e8 100644 --- a/src/karapace/kafka_rest_apis/consumer_manager.py +++ b/src/karapace/kafka_rest_apis/consumer_manager.py @@ -240,7 +240,7 @@ async def create_kafka_consumer(self, fetch_min_bytes, group_name, client_id: st ) await c.start() return c - except: # pylint: disable=bare-except + except Exception: if retry: LOG.warning("Unable to create consumer, retrying") else: @@ -256,7 +256,7 @@ async def delete_consumer(self, internal_name: tuple[str, str], content_type: st c = self.consumers.pop(internal_name) await c.consumer.stop() self.consumer_locks.pop(internal_name) - except: # pylint: disable=bare-except + except Exception: LOG.exception("Unable to properly dispose of consumer") finally: empty_response() @@ -597,5 +597,5 @@ async def aclose(self): c = self.consumers.pop(k) try: await c.consumer.stop() - except: # pylint: disable=bare-except + except Exception: pass diff --git a/src/karapace/rapu.py b/src/karapace/rapu.py index 39504be3c..83666f344 100644 --- a/src/karapace/rapu.py +++ b/src/karapace/rapu.py @@ -350,7 +350,7 @@ async def _handle_request( except asyncio.CancelledError: # Re-raise if aiohttp cancelled the task (e.g. client disconnected) without internal server error raise - except: # pylint: disable=bare-except + except Exception: self.log.exception("Internal server error") headers = {"Content-Type": "application/json"} data = {"error_code": HTTPStatus.INTERNAL_SERVER_ERROR.value, "message": "Internal server error"} diff --git a/src/schema_registry/messaging.py b/src/schema_registry/messaging.py index af4a745df..a5cdf0fc1 100644 --- a/src/schema_registry/messaging.py +++ b/src/schema_registry/messaging.py @@ -51,7 +51,7 @@ def initialize_karapace_producer( connections_max_idle_ms=self._config.connections_max_idle_ms, # helps through cluster upgrades ?? ) return - except: # pylint: disable=bare-except + except Exception: LOG.exception("Unable to create producer, retrying") time.sleep(1) diff --git a/src/schema_registry/reader.py b/src/schema_registry/reader.py index 67c9e4dc8..7525a0c95 100644 --- a/src/schema_registry/reader.py +++ b/src/schema_registry/reader.py @@ -252,7 +252,7 @@ def run(self) -> None: self.config.topic_name, ) self._stop_schema_reader.wait(timeout=SCHEMA_TOPIC_CREATION_TIMEOUT_SECONDS) - except: # pylint: disable=bare-except + except Exception: LOG.exception("[Schema Topic] Failed to create %r, retrying", self.config.topic_name) self._stop_schema_reader.wait(timeout=SCHEMA_TOPIC_CREATION_TIMEOUT_SECONDS) diff --git a/tests/integration/test_schema_coordinator.py b/tests/integration/test_schema_coordinator.py index d8b02c0c9..81d106d6d 100644 --- a/tests/integration/test_schema_coordinator.py +++ b/tests/integration/test_schema_coordinator.py @@ -76,7 +76,7 @@ async def _get_client(kafka_servers: KafkaServers) -> AIOKafkaClient: client = AIOKafkaClient(bootstrap_servers=",".join(kafka_servers.bootstrap_servers)) await client.bootstrap() break - except: # pylint: disable=bare-except + except Exception: LOG.exception("Kafka client bootstrap failed.") await asyncio.sleep(0.5) return client From bdb5f5c5de462cadd1c7c075b4844f8d8a03c5aa Mon Sep 17 00:00:00 2001 From: Jarkko Jaakola Date: Wed, 8 Jan 2025 12:16:05 +0200 Subject: [PATCH 2/3] chore: format with ruff --- container/healthcheck.py | 1 + .../rest-proxy-produce-consume-test.py | 1 + .../schema-registry-schema-post.py | 1 + setup.py | 1 + .../anonymize_schemas/anonymize_avro.py | 1 + src/karapace/auth.py | 16 +++++------- src/karapace/avro_dataclasses/introspect.py | 9 +++---- src/karapace/avro_dataclasses/models.py | 4 +-- src/karapace/avro_dataclasses/schema.py | 1 + src/karapace/backup/api.py | 1 + src/karapace/backup/backends/reader.py | 4 +-- src/karapace/backup/backends/v1.py | 1 + src/karapace/backup/backends/v2.py | 1 + src/karapace/backup/backends/v3/backend.py | 1 + src/karapace/backup/backends/v3/checksum.py | 7 +++--- src/karapace/backup/backends/v3/constants.py | 1 + src/karapace/backup/backends/v3/readers.py | 1 + src/karapace/backup/backends/v3/schema.py | 1 + .../backup/backends/v3/schema_tool.py | 1 + src/karapace/backup/backends/v3/writers.py | 1 + src/karapace/backup/backends/writer.py | 4 +-- src/karapace/backup/cli.py | 1 + src/karapace/backup/encoders.py | 1 + src/karapace/backup/errors.py | 4 +-- src/karapace/backup/poll_timeout.py | 1 + src/karapace/backup/safe_writer.py | 4 +-- src/karapace/backup/topic_configurations.py | 1 + src/karapace/client.py | 1 + src/karapace/compatibility/__init__.py | 1 + .../compatibility/jsonschema/checks.py | 1 + .../compatibility/jsonschema/types.py | 1 + .../compatibility/jsonschema/utils.py | 1 + src/karapace/compatibility/protobuf/checks.py | 1 + .../compatibility/schema_compatibility.py | 1 + src/karapace/config.py | 1 + src/karapace/constants.py | 1 + .../coordinator/master_coordinator.py | 1 + .../coordinator/schema_coordinator.py | 1 + src/karapace/dataclasses.py | 1 + src/karapace/forward_client.py | 6 ++--- src/karapace/in_memory_database.py | 1 + src/karapace/kafka/common.py | 6 ++--- src/karapace/kafka_rest_apis/__init__.py | 1 + .../kafka_rest_apis/authentication.py | 1 + .../kafka_rest_apis/consumer_manager.py | 1 + src/karapace/kafka_rest_apis/error_codes.py | 1 + src/karapace/kafka_utils.py | 1 + src/karapace/karapace_all.py | 1 + src/karapace/protobuf/compare_result.py | 1 + src/karapace/protobuf/compare_type_lists.py | 1 + src/karapace/protobuf/compare_type_storage.py | 1 + src/karapace/protobuf/enum_element.py | 1 + src/karapace/protobuf/exception.py | 1 + src/karapace/protobuf/extend_element.py | 1 + src/karapace/protobuf/group_element.py | 1 + src/karapace/protobuf/io.py | 18 +++++++------ src/karapace/protobuf/kotlin_wrapper.py | 1 + src/karapace/protobuf/message_element.py | 1 + src/karapace/protobuf/option_element.py | 1 + src/karapace/protobuf/option_reader.py | 1 + src/karapace/protobuf/proto_file_element.py | 1 + src/karapace/protobuf/proto_type.py | 1 + src/karapace/protobuf/protobuf_to_dict.py | 1 + src/karapace/protobuf/reserved_element.py | 1 + src/karapace/protobuf/serialization.py | 1 + src/karapace/protobuf/service_element.py | 1 + src/karapace/protobuf/syntax_reader.py | 1 + src/karapace/protobuf/type_element.py | 1 + src/karapace/protobuf/type_tree.py | 1 + src/karapace/protobuf/utils.py | 1 + src/karapace/rapu.py | 7 +++--- src/karapace/schema_models.py | 1 + src/karapace/sentry/sentry_client.py | 1 + src/karapace/sentry/sentry_client_api.py | 1 + src/karapace/serialization.py | 1 + src/karapace/statsd.py | 1 + src/karapace/typing.py | 1 + src/karapace/utils.py | 25 +++++++------------ src/schema_registry/__main__.py | 1 + src/schema_registry/controller.py | 1 + src/schema_registry/factory.py | 1 + src/schema_registry/messaging.py | 1 + src/schema_registry/reader.py | 1 + src/schema_registry/registry.py | 1 + tests/conftest.py | 1 + tests/e2e/conftest.py | 1 + tests/e2e/kafka/test_consumer.py | 1 + tests/e2e/schema_registry/test_jsonschema.py | 1 + tests/e2e/test_karapace.py | 1 + tests/integration/backup/test_avro_export.py | 1 + .../backup/test_get_topic_configurations.py | 1 + .../integration/backup/test_legacy_backup.py | 1 + .../backup/test_session_timeout.py | 1 + tests/integration/backup/test_v3_backup.py | 1 + tests/integration/conftest.py | 1 + tests/integration/test_client.py | 1 + tests/integration/test_client_protobuf.py | 1 + ...est_dependencies_compatibility_protobuf.py | 1 + tests/integration/test_master_coordinator.py | 1 + tests/integration/test_rest.py | 1 + tests/integration/test_rest_consumer.py | 1 + tests/integration/test_schema.py | 1 + .../integration/test_schema_compatibility.py | 4 ++- tests/integration/test_schema_coordinator.py | 7 ++++-- tests/integration/test_schema_protobuf.py | 1 + tests/integration/test_schema_reader.py | 1 + .../integration/test_schema_registry_auth.py | 1 + .../integration/test_schema_registry_mode.py | 1 + tests/integration/utils/cluster.py | 1 + tests/integration/utils/config.py | 1 + tests/integration/utils/kafka_server.py | 1 + tests/integration/utils/network.py | 1 + tests/integration/utils/process.py | 1 + tests/integration/utils/rest_client.py | 1 + tests/integration/utils/synchronization.py | 1 + tests/integration/utils/zookeeper.py | 1 + tests/schemas/json_schemas.py | 1 + tests/schemas/protobuf.py | 1 + .../anonymize_schemas/test_anonymize_avro.py | 1 + .../unit/avro_dataclasses/test_introspect.py | 1 + tests/unit/avro_dataclasses/test_models.py | 1 + tests/unit/backup/backends/test_v1.py | 1 + tests/unit/backup/backends/test_v2.py | 1 + tests/unit/backup/backends/v3/conftest.py | 1 + tests/unit/backup/backends/v3/test_backend.py | 1 + .../backup/backends/v3/test_serialisation.py | 1 + tests/unit/backup/test_api.py | 1 + tests/unit/backup/test_encoders.py | 1 + tests/unit/backup/test_poll_timeout.py | 1 + tests/unit/backup/test_safe_writer.py | 1 + .../test_jsonschema_compatibility.py | 1 + .../unit/compatibility/test_compatibility.py | 1 + tests/unit/protobuf/test_compare_elements.py | 1 + tests/unit/protobuf/test_dependency.py | 1 + tests/unit/protobuf/test_io.py | 1 + .../unit/protobuf/test_proto_file_element.py | 1 + tests/unit/protobuf/test_proto_parser.py | 8 +++--- .../protobuf/test_protobuf_compatibility.py | 1 + tests/unit/protobuf/test_protobuf_schema.py | 1 + .../protobuf/test_protobuf_schema_name.py | 1 + tests/unit/protobuf/test_protoc.py | 1 + tests/unit/schema_registry/test_controller.py | 1 + tests/unit/test_auth.py | 1 + tests/unit/test_authentication.py | 1 + tests/unit/test_avro_compatibility.py | 1 + tests/unit/test_config.py | 1 + tests/unit/test_features.py | 1 + tests/unit/test_forwarding_client.py | 1 + tests/unit/test_in_memory_database.py | 1 + tests/unit/test_kafka_error_handler.py | 1 + .../test_protobuf_binary_serialization.py | 1 + tests/unit/test_protobuf_serialization.py | 1 + tests/unit/test_rapu.py | 1 + tests/unit/test_rest_auth.py | 1 + tests/unit/test_serialization.py | 1 + tests/unit/test_utils.py | 1 + tests/utils.py | 1 + 157 files changed, 202 insertions(+), 72 deletions(-) diff --git a/container/healthcheck.py b/container/healthcheck.py index 2d08fb29d..08f8c6a5d 100644 --- a/container/healthcheck.py +++ b/container/healthcheck.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from http import HTTPStatus diff --git a/performance-test/rest-proxy-produce-consume-test.py b/performance-test/rest-proxy-produce-consume-test.py index 669b38f69..77c5b0a8f 100644 --- a/performance-test/rest-proxy-produce-consume-test.py +++ b/performance-test/rest-proxy-produce-consume-test.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from kafka.admin import KafkaAdminClient, NewTopic from kafka.errors import TopicAlreadyExistsError from locust import FastHttpUser, task diff --git a/performance-test/schema-registry-schema-post.py b/performance-test/schema-registry-schema-post.py index b3fd795ff..070b8773d 100644 --- a/performance-test/schema-registry-schema-post.py +++ b/performance-test/schema-registry-schema-post.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from dataclasses import dataclass, field from locust import FastHttpUser, task from locust.contrib.fasthttp import ResponseContextManager diff --git a/setup.py b/setup.py index ad992e355..41a151c1c 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from setuptools import Extension, setup setup( diff --git a/src/karapace/anonymize_schemas/anonymize_avro.py b/src/karapace/anonymize_schemas/anonymize_avro.py index a5521464b..79d3f5d1a 100644 --- a/src/karapace/anonymize_schemas/anonymize_avro.py +++ b/src/karapace/anonymize_schemas/anonymize_avro.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from typing import Any, TypeAlias, Union import hashlib diff --git a/src/karapace/auth.py b/src/karapace/auth.py index 607ab0ea3..9c2a34218 100644 --- a/src/karapace/auth.py +++ b/src/karapace/auth.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from base64 import b64encode @@ -98,26 +99,21 @@ class AuthData(TypedDict): class AuthenticateProtocol(Protocol): - def authenticate(self, *, username: str, password: str) -> User | None: - ... + def authenticate(self, *, username: str, password: str) -> User | None: ... class AuthorizeProtocol(Protocol): - def get_user(self, username: str) -> User | None: - ... + def get_user(self, username: str) -> User | None: ... - def check_authorization(self, user: User | None, operation: Operation, resource: str) -> bool: - ... + def check_authorization(self, user: User | None, operation: Operation, resource: str) -> bool: ... - def check_authorization_any(self, user: User | None, operation: Operation, resources: list[str]) -> bool: - ... + def check_authorization_any(self, user: User | None, operation: Operation, resources: list[str]) -> bool: ... class AuthenticatorAndAuthorizer(AuthenticateProtocol, AuthorizeProtocol): MUST_AUTHENTICATE: bool = True - async def close(self) -> None: - ... + async def close(self) -> None: ... async def start(self, stats: StatsClient) -> None: # pylint: disable=unused-argument ... diff --git a/src/karapace/avro_dataclasses/introspect.py b/src/karapace/avro_dataclasses/introspect.py index 254a5bc71..9eb4ec85f 100644 --- a/src/karapace/avro_dataclasses/introspect.py +++ b/src/karapace/avro_dataclasses/introspect.py @@ -20,16 +20,13 @@ from _typeshed import DataclassInstance else: - class DataclassInstance: - ... + class DataclassInstance: ... -class UnsupportedAnnotation(NotImplementedError): - ... +class UnsupportedAnnotation(NotImplementedError): ... -class UnderspecifiedAnnotation(UnsupportedAnnotation): - ... +class UnderspecifiedAnnotation(UnsupportedAnnotation): ... def _field_type_array(field: Field, origin: type, type_: object) -> AvroType: diff --git a/src/karapace/avro_dataclasses/models.py b/src/karapace/avro_dataclasses/models.py index 46fa477a0..719871920 100644 --- a/src/karapace/avro_dataclasses/models.py +++ b/src/karapace/avro_dataclasses/models.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from .introspect import record_schema @@ -22,8 +23,7 @@ from _typeshed import DataclassInstance else: - class DataclassInstance: - ... + class DataclassInstance: ... __all__ = ("AvroModel",) diff --git a/src/karapace/avro_dataclasses/schema.py b/src/karapace/avro_dataclasses/schema.py index 31990b601..6d47af552 100644 --- a/src/karapace/avro_dataclasses/schema.py +++ b/src/karapace/avro_dataclasses/schema.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Mapping diff --git a/src/karapace/backup/api.py b/src/karapace/backup/api.py index 60be1b966..7f74d7cb8 100644 --- a/src/karapace/backup/api.py +++ b/src/karapace/backup/api.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from .backends.reader import BaseBackupReader, BaseItemsBackupReader, ProducerSend, RestoreTopic, RestoreTopicLegacy diff --git a/src/karapace/backup/backends/reader.py b/src/karapace/backup/backends/reader.py index b803e596d..2047f71d2 100644 --- a/src/karapace/backup/backends/reader.py +++ b/src/karapace/backup/backends/reader.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Callable, Generator, Iterator, Mapping, Sequence @@ -78,8 +79,7 @@ def __init__( @staticmethod @abc.abstractmethod - def items_from_file(fp: IO[str]) -> Iterator[Sequence[str]]: - ... + def items_from_file(fp: IO[str]) -> Iterator[Sequence[str]]: ... def read( self, diff --git a/src/karapace/backup/backends/v1.py b/src/karapace/backup/backends/v1.py index 186af0c0b..9416e2b94 100644 --- a/src/karapace/backup/backends/v1.py +++ b/src/karapace/backup/backends/v1.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Generator diff --git a/src/karapace/backup/backends/v2.py b/src/karapace/backup/backends/v2.py index a456d6e39..9c3b8307d 100644 --- a/src/karapace/backup/backends/v2.py +++ b/src/karapace/backup/backends/v2.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Generator, Sequence diff --git a/src/karapace/backup/backends/v3/backend.py b/src/karapace/backup/backends/v3/backend.py index 45c9855bc..e5a2cca62 100644 --- a/src/karapace/backup/backends/v3/backend.py +++ b/src/karapace/backup/backends/v3/backend.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from .checksum import RunningChecksum diff --git a/src/karapace/backup/backends/v3/checksum.py b/src/karapace/backup/backends/v3/checksum.py index 4c550070e..4555d1237 100644 --- a/src/karapace/backup/backends/v3/checksum.py +++ b/src/karapace/backup/backends/v3/checksum.py @@ -2,14 +2,13 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from typing import Protocol class RunningChecksum(Protocol): - def update(self, data: bytes) -> None: - ... + def update(self, data: bytes) -> None: ... - def digest(self) -> bytes: - ... + def digest(self) -> bytes: ... diff --git a/src/karapace/backup/backends/v3/constants.py b/src/karapace/backup/backends/v3/constants.py index fd0ac334c..f7219cb7d 100644 --- a/src/karapace/backup/backends/v3/constants.py +++ b/src/karapace/backup/backends/v3/constants.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from typing import Final V3_MARKER: Final = b"/V3\n" diff --git a/src/karapace/backup/backends/v3/readers.py b/src/karapace/backup/backends/v3/readers.py index 74b981143..80136fa28 100644 --- a/src/karapace/backup/backends/v3/readers.py +++ b/src/karapace/backup/backends/v3/readers.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from .checksum import RunningChecksum diff --git a/src/karapace/backup/backends/v3/schema.py b/src/karapace/backup/backends/v3/schema.py index b979d6472..f8494f45a 100644 --- a/src/karapace/backup/backends/v3/schema.py +++ b/src/karapace/backup/backends/v3/schema.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from collections.abc import Mapping from dataclasses import field from karapace.avro_dataclasses.models import AvroModel diff --git a/src/karapace/backup/backends/v3/schema_tool.py b/src/karapace/backup/backends/v3/schema_tool.py index f5843ceb2..bbbc1a9a0 100644 --- a/src/karapace/backup/backends/v3/schema_tool.py +++ b/src/karapace/backup/backends/v3/schema_tool.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from . import schema from avro.compatibility import ReaderWriterCompatibilityChecker, SchemaCompatibilityType from collections.abc import Generator diff --git a/src/karapace/backup/backends/v3/writers.py b/src/karapace/backup/backends/v3/writers.py index 0dadc8fe4..b42645cbb 100644 --- a/src/karapace/backup/backends/v3/writers.py +++ b/src/karapace/backup/backends/v3/writers.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from .checksum import RunningChecksum from .constants import V3_MARKER from .errors import IntegerAboveBound, IntegerBelowBound diff --git a/src/karapace/backup/backends/writer.py b/src/karapace/backup/backends/writer.py index 2bbf88ce5..78dd330e3 100644 --- a/src/karapace/backup/backends/writer.py +++ b/src/karapace/backup/backends/writer.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Iterator, Mapping, Sequence @@ -170,5 +171,4 @@ def store_record( def serialize_record( key_bytes: bytes | None, value_bytes: bytes | None, - ) -> str: - ... + ) -> str: ... diff --git a/src/karapace/backup/cli.py b/src/karapace/backup/cli.py index 9ae73ba75..0f172da8e 100644 --- a/src/karapace/backup/cli.py +++ b/src/karapace/backup/cli.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from . import api diff --git a/src/karapace/backup/encoders.py b/src/karapace/backup/encoders.py index 66369f6fa..78f9c0af0 100644 --- a/src/karapace/backup/encoders.py +++ b/src/karapace/backup/encoders.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from karapace.key_format import KeyFormatter diff --git a/src/karapace/backup/errors.py b/src/karapace/backup/errors.py index 78d406626..10f9e2c72 100644 --- a/src/karapace/backup/errors.py +++ b/src/karapace/backup/errors.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from confluent_kafka import TopicPartition from karapace.backup.poll_timeout import PollTimeout @@ -12,8 +13,7 @@ class BackupError(Exception): """Baseclass for all backup errors.""" -class EmptyPartition(BackupError): - ... +class EmptyPartition(BackupError): ... class PartitionCountError(BackupError): diff --git a/src/karapace/backup/poll_timeout.py b/src/karapace/backup/poll_timeout.py index 91d5871f1..2cfefca9b 100644 --- a/src/karapace/backup/poll_timeout.py +++ b/src/karapace/backup/poll_timeout.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from datetime import timedelta diff --git a/src/karapace/backup/safe_writer.py b/src/karapace/backup/safe_writer.py index 78e08ea99..49f4da8d8 100644 --- a/src/karapace/backup/safe_writer.py +++ b/src/karapace/backup/safe_writer.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Generator @@ -19,8 +20,7 @@ std_out_alias: Final = ("", "-") -class OverwriteRefused(Exception): - ... +class OverwriteRefused(Exception): ... def _check_destination_file(destination: Path, allow_overwrite: bool) -> None: diff --git a/src/karapace/backup/topic_configurations.py b/src/karapace/backup/topic_configurations.py index 5aaf13a52..9fdc7d3b1 100644 --- a/src/karapace/backup/topic_configurations.py +++ b/src/karapace/backup/topic_configurations.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Container diff --git a/src/karapace/client.py b/src/karapace/client.py index 857f6221a..22fd563a9 100644 --- a/src/karapace/client.py +++ b/src/karapace/client.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from aiohttp import BasicAuth, ClientSession from collections.abc import Awaitable, Callable, Mapping from karapace.typing import JsonData diff --git a/src/karapace/compatibility/__init__.py b/src/karapace/compatibility/__init__.py index 3984ed9f5..2ad0d47db 100644 --- a/src/karapace/compatibility/__init__.py +++ b/src/karapace/compatibility/__init__.py @@ -4,6 +4,7 @@ Copyright (c) 2019 Aiven Ltd See LICENSE for details """ + from enum import Enum, unique import logging diff --git a/src/karapace/compatibility/jsonschema/checks.py b/src/karapace/compatibility/jsonschema/checks.py index 483da7f85..582c7e8e1 100644 --- a/src/karapace/compatibility/jsonschema/checks.py +++ b/src/karapace/compatibility/jsonschema/checks.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from avro.compatibility import merge, SchemaCompatibilityResult, SchemaCompatibilityType, SchemaIncompatibilityType diff --git a/src/karapace/compatibility/jsonschema/types.py b/src/karapace/compatibility/jsonschema/types.py index 9d8b7fc14..f25741d14 100644 --- a/src/karapace/compatibility/jsonschema/types.py +++ b/src/karapace/compatibility/jsonschema/types.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from collections.abc import Callable from dataclasses import dataclass from enum import Enum, unique diff --git a/src/karapace/compatibility/jsonschema/utils.py b/src/karapace/compatibility/jsonschema/utils.py index b26bf8843..fe1f1f467 100644 --- a/src/karapace/compatibility/jsonschema/utils.py +++ b/src/karapace/compatibility/jsonschema/utils.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from copy import copy from jsonschema import Draft7Validator from karapace.compatibility.jsonschema.types import BooleanSchema, Instance, Keyword, Subschema diff --git a/src/karapace/compatibility/protobuf/checks.py b/src/karapace/compatibility/protobuf/checks.py index b463b72ce..243c9004d 100644 --- a/src/karapace/compatibility/protobuf/checks.py +++ b/src/karapace/compatibility/protobuf/checks.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from avro.compatibility import SchemaCompatibilityResult, SchemaCompatibilityType from karapace.protobuf.compare_result import CompareResult from karapace.protobuf.schema import ProtobufSchema diff --git a/src/karapace/compatibility/schema_compatibility.py b/src/karapace/compatibility/schema_compatibility.py index 07e059d50..b776c26a5 100644 --- a/src/karapace/compatibility/schema_compatibility.py +++ b/src/karapace/compatibility/schema_compatibility.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from avro.compatibility import ( merge, ReaderWriterCompatibilityChecker as AvroChecker, diff --git a/src/karapace/config.py b/src/karapace/config.py index be9d60454..ce5c727b8 100644 --- a/src/karapace/config.py +++ b/src/karapace/config.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Mapping diff --git a/src/karapace/constants.py b/src/karapace/constants.py index e18a6e574..50acecc53 100644 --- a/src/karapace/constants.py +++ b/src/karapace/constants.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from typing import Final SCHEMA_TOPIC_NUM_PARTITIONS: Final = 1 diff --git a/src/karapace/coordinator/master_coordinator.py b/src/karapace/coordinator/master_coordinator.py index 64341d1d1..2ac449b06 100644 --- a/src/karapace/coordinator/master_coordinator.py +++ b/src/karapace/coordinator/master_coordinator.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from aiokafka import AIOKafkaClient diff --git a/src/karapace/coordinator/schema_coordinator.py b/src/karapace/coordinator/schema_coordinator.py index d99f1c79f..a7624380a 100644 --- a/src/karapace/coordinator/schema_coordinator.py +++ b/src/karapace/coordinator/schema_coordinator.py @@ -4,6 +4,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from aiokafka.client import AIOKafkaClient, ConnectionGroup diff --git a/src/karapace/dataclasses.py b/src/karapace/dataclasses.py index d6be6c5c7..7a815dcc5 100644 --- a/src/karapace/dataclasses.py +++ b/src/karapace/dataclasses.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from dataclasses import dataclass diff --git a/src/karapace/forward_client.py b/src/karapace/forward_client.py index cb331c148..3b91e5640 100644 --- a/src/karapace/forward_client.py +++ b/src/karapace/forward_client.py @@ -70,8 +70,7 @@ async def forward_request_remote( request: Request, primary_url: str, response_type: type[BaseModelResponse], - ) -> BaseModelResponse: - ... + ) -> BaseModelResponse: ... @overload async def forward_request_remote( @@ -80,8 +79,7 @@ async def forward_request_remote( request: Request, primary_url: str, response_type: type[SimpleTypeResponse], - ) -> SimpleTypeResponse: - ... + ) -> SimpleTypeResponse: ... async def forward_request_remote( self, diff --git a/src/karapace/in_memory_database.py b/src/karapace/in_memory_database.py index 6692cae33..ae0439541 100644 --- a/src/karapace/in_memory_database.py +++ b/src/karapace/in_memory_database.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from abc import ABC, abstractmethod diff --git a/src/karapace/kafka/common.py b/src/karapace/kafka/common.py index c541cbac3..fd5441d16 100644 --- a/src/karapace/kafka/common.py +++ b/src/karapace/kafka/common.py @@ -80,8 +80,7 @@ def raise_from_kafkaexception(exc: KafkaException) -> NoReturn: # `karapace.kafka_rest_apis.authentication.SimpleOauthTokenProvider` # to avoid circular imports class TokenWithExpiryProvider(Protocol): - def token_with_expiry(self, config: str | None) -> tuple[str, int | None]: - ... + def token_with_expiry(self, config: str | None) -> tuple[str, int | None]: ... class KafkaClientParams(TypedDict, total=False): @@ -209,7 +208,8 @@ def _verify_connection(self) -> None: self._activate_callbacks() self.log.info("Could not establish connection due to errors: %s", self._errors) if any( - error.code() == KafkaError._AUTHENTICATION for error in self._errors # pylint: disable=protected-access + error.code() == KafkaError._AUTHENTICATION + for error in self._errors # pylint: disable=protected-access ): raise AuthenticationFailedError() from exc continue diff --git a/src/karapace/kafka_rest_apis/__init__.py b/src/karapace/kafka_rest_apis/__init__.py index f2f4f485d..14d145b7e 100644 --- a/src/karapace/kafka_rest_apis/__init__.py +++ b/src/karapace/kafka_rest_apis/__init__.py @@ -4,6 +4,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from aiokafka.errors import ( diff --git a/src/karapace/kafka_rest_apis/authentication.py b/src/karapace/kafka_rest_apis/authentication.py index 5b1a14425..9c628130a 100644 --- a/src/karapace/kafka_rest_apis/authentication.py +++ b/src/karapace/kafka_rest_apis/authentication.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from http import HTTPStatus diff --git a/src/karapace/kafka_rest_apis/consumer_manager.py b/src/karapace/kafka_rest_apis/consumer_manager.py index 0b26af7e8..68280a963 100644 --- a/src/karapace/kafka_rest_apis/consumer_manager.py +++ b/src/karapace/kafka_rest_apis/consumer_manager.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from aiokafka.errors import ( GroupAuthorizationFailedError, IllegalStateError, diff --git a/src/karapace/kafka_rest_apis/error_codes.py b/src/karapace/kafka_rest_apis/error_codes.py index f57a10f3c..b4cfba70c 100644 --- a/src/karapace/kafka_rest_apis/error_codes.py +++ b/src/karapace/kafka_rest_apis/error_codes.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from enum import Enum from http import HTTPStatus diff --git a/src/karapace/kafka_utils.py b/src/karapace/kafka_utils.py index 02eed2e64..f69e6ef4d 100644 --- a/src/karapace/kafka_utils.py +++ b/src/karapace/kafka_utils.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from .config import Config from collections.abc import Iterator from karapace.kafka.admin import KafkaAdminClient diff --git a/src/karapace/karapace_all.py b/src/karapace/karapace_all.py index 8090216e9..3f243688a 100644 --- a/src/karapace/karapace_all.py +++ b/src/karapace/karapace_all.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from dependency_injector.wiring import inject, Provide diff --git a/src/karapace/protobuf/compare_result.py b/src/karapace/protobuf/compare_result.py index 1caffdc24..604adb0c6 100644 --- a/src/karapace/protobuf/compare_result.py +++ b/src/karapace/protobuf/compare_result.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from dataclasses import dataclass, field from enum import auto, Enum diff --git a/src/karapace/protobuf/compare_type_lists.py b/src/karapace/protobuf/compare_type_lists.py index 788d272ad..bb37a2203 100644 --- a/src/karapace/protobuf/compare_type_lists.py +++ b/src/karapace/protobuf/compare_type_lists.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from collections.abc import Sequence from itertools import chain from karapace.protobuf.compare_result import CompareResult, Modification diff --git a/src/karapace/protobuf/compare_type_storage.py b/src/karapace/protobuf/compare_type_storage.py index a48a8993f..3e212203d 100644 --- a/src/karapace/protobuf/compare_type_storage.py +++ b/src/karapace/protobuf/compare_type_storage.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from dataclasses import dataclass from karapace.protobuf.compare_result import CompareResult from karapace.protobuf.exception import IllegalArgumentException diff --git a/src/karapace/protobuf/enum_element.py b/src/karapace/protobuf/enum_element.py index 38c8a87c4..bcc2536c8 100644 --- a/src/karapace/protobuf/enum_element.py +++ b/src/karapace/protobuf/enum_element.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/EnumElement.kt from __future__ import annotations diff --git a/src/karapace/protobuf/exception.py b/src/karapace/protobuf/exception.py index 58569bac9..d6364d7ea 100644 --- a/src/karapace/protobuf/exception.py +++ b/src/karapace/protobuf/exception.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from typing import TYPE_CHECKING diff --git a/src/karapace/protobuf/extend_element.py b/src/karapace/protobuf/extend_element.py index 748d85d7e..424bf5769 100644 --- a/src/karapace/protobuf/extend_element.py +++ b/src/karapace/protobuf/extend_element.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ExtendElement.kt from __future__ import annotations diff --git a/src/karapace/protobuf/group_element.py b/src/karapace/protobuf/group_element.py index 0db09e41f..785a6f956 100644 --- a/src/karapace/protobuf/group_element.py +++ b/src/karapace/protobuf/group_element.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/GroupElement.kt from __future__ import annotations diff --git a/src/karapace/protobuf/io.py b/src/karapace/protobuf/io.py index d58c52415..ee22dacc1 100644 --- a/src/karapace/protobuf/io.py +++ b/src/karapace/protobuf/io.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Generator, Iterable @@ -65,10 +66,13 @@ def _crawl_dependencies( # todo: https://github.com/aiven/karapace/issues/641 assert isinstance(dependency.schema.schema, ProtobufSchema) yield from _crawl_dependencies(dependency.schema.schema) - yield name, { - "schema": str(dependency.schema.schema), - "unique_class_name": calculate_class_name(f"{dependency.version}_{dependency.name}"), - } + yield ( + name, + { + "schema": str(dependency.schema.schema), + "unique_class_name": calculate_class_name(f"{dependency.version}_{dependency.name}"), + }, + ) def crawl_dependencies(schema: ProtobufSchema) -> dict[str, dict[str, str]]: @@ -85,11 +89,9 @@ def replace_imports(string: str, deps_list: dict[str, dict[str, str]] | None) -> class _ProtobufModel(Protocol): - def ParseFromString(self, buffer: bytes) -> Self: - ... + def ParseFromString(self, buffer: bytes) -> Self: ... - def SerializeToString(self) -> bytes: - ... + def SerializeToString(self) -> bytes: ... def get_protobuf_class_instance( diff --git a/src/karapace/protobuf/kotlin_wrapper.py b/src/karapace/protobuf/kotlin_wrapper.py index ef94c6ef0..693044c77 100644 --- a/src/karapace/protobuf/kotlin_wrapper.py +++ b/src/karapace/protobuf/kotlin_wrapper.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from dataclasses import dataclass import textwrap diff --git a/src/karapace/protobuf/message_element.py b/src/karapace/protobuf/message_element.py index d3333b47b..79538231d 100644 --- a/src/karapace/protobuf/message_element.py +++ b/src/karapace/protobuf/message_element.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/MessageElement.kt # compatibility routine added diff --git a/src/karapace/protobuf/option_element.py b/src/karapace/protobuf/option_element.py index 70622d5ef..7ae66b5c3 100644 --- a/src/karapace/protobuf/option_element.py +++ b/src/karapace/protobuf/option_element.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OptionElement.kt from __future__ import annotations diff --git a/src/karapace/protobuf/option_reader.py b/src/karapace/protobuf/option_reader.py index a3e12b614..dc26317e1 100644 --- a/src/karapace/protobuf/option_reader.py +++ b/src/karapace/protobuf/option_reader.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OptionReader.kt from dataclasses import dataclass diff --git a/src/karapace/protobuf/proto_file_element.py b/src/karapace/protobuf/proto_file_element.py index 889b577b0..7e547c544 100644 --- a/src/karapace/protobuf/proto_file_element.py +++ b/src/karapace/protobuf/proto_file_element.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from collections.abc import Sequence # Ported from square/wire: diff --git a/src/karapace/protobuf/proto_type.py b/src/karapace/protobuf/proto_type.py index 9eb97ce4e..154cc18e7 100644 --- a/src/karapace/protobuf/proto_type.py +++ b/src/karapace/protobuf/proto_type.py @@ -5,6 +5,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoType.kt from enum import auto, Enum diff --git a/src/karapace/protobuf/protobuf_to_dict.py b/src/karapace/protobuf/protobuf_to_dict.py index 22fc300d6..8d2845f3a 100644 --- a/src/karapace/protobuf/protobuf_to_dict.py +++ b/src/karapace/protobuf/protobuf_to_dict.py @@ -7,6 +7,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from dateutil.parser import parse as date_parser from google.protobuf.descriptor import FieldDescriptor from google.protobuf.message import Message diff --git a/src/karapace/protobuf/reserved_element.py b/src/karapace/protobuf/reserved_element.py index bd1a6846e..761356484 100644 --- a/src/karapace/protobuf/reserved_element.py +++ b/src/karapace/protobuf/reserved_element.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ReservedElement.kt from __future__ import annotations diff --git a/src/karapace/protobuf/serialization.py b/src/karapace/protobuf/serialization.py index 123e80c8f..19ff442ea 100644 --- a/src/karapace/protobuf/serialization.py +++ b/src/karapace/protobuf/serialization.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Sequence diff --git a/src/karapace/protobuf/service_element.py b/src/karapace/protobuf/service_element.py index 08f365b8b..ffb04fc0f 100644 --- a/src/karapace/protobuf/service_element.py +++ b/src/karapace/protobuf/service_element.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ServiceElement.kt from __future__ import annotations diff --git a/src/karapace/protobuf/syntax_reader.py b/src/karapace/protobuf/syntax_reader.py index 4c43237d0..99ecaba79 100644 --- a/src/karapace/protobuf/syntax_reader.py +++ b/src/karapace/protobuf/syntax_reader.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/SyntaxReader.kt from karapace.protobuf.exception import IllegalStateException diff --git a/src/karapace/protobuf/type_element.py b/src/karapace/protobuf/type_element.py index 89e999034..12832ed6d 100644 --- a/src/karapace/protobuf/type_element.py +++ b/src/karapace/protobuf/type_element.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/TypeElement.kt from __future__ import annotations diff --git a/src/karapace/protobuf/type_tree.py b/src/karapace/protobuf/type_tree.py index 71fe83b3d..935d1b57b 100644 --- a/src/karapace/protobuf/type_tree.py +++ b/src/karapace/protobuf/type_tree.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Iterable, Sequence diff --git a/src/karapace/protobuf/utils.py b/src/karapace/protobuf/utils.py index 081a23c87..06455903b 100644 --- a/src/karapace/protobuf/utils.py +++ b/src/karapace/protobuf/utils.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/Util.kt from typing import TYPE_CHECKING diff --git a/src/karapace/rapu.py b/src/karapace/rapu.py index 83666f344..f31e8aab9 100644 --- a/src/karapace/rapu.py +++ b/src/karapace/rapu.py @@ -6,6 +6,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from accept_types import get_best_match from collections.abc import Callable from http import HTTPStatus @@ -81,12 +82,10 @@ def __init__( self.json: dict | None = None @overload - def get_header(self, header: str) -> str | None: - ... + def get_header(self, header: str) -> str | None: ... @overload - def get_header(self, header: str, default_value: str) -> str: - ... + def get_header(self, header: str, default_value: str) -> str: ... def get_header(self, header, default_value=None): upper_cased = header.upper() diff --git a/src/karapace/schema_models.py b/src/karapace/schema_models.py index 10ffa1d82..c4cc073a9 100644 --- a/src/karapace/schema_models.py +++ b/src/karapace/schema_models.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from avro.errors import SchemaParseException diff --git a/src/karapace/sentry/sentry_client.py b/src/karapace/sentry/sentry_client.py index c4dc99d33..3ef328132 100644 --- a/src/karapace/sentry/sentry_client.py +++ b/src/karapace/sentry/sentry_client.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Mapping diff --git a/src/karapace/sentry/sentry_client_api.py b/src/karapace/sentry/sentry_client_api.py index b423c189a..1ebe4808c 100644 --- a/src/karapace/sentry/sentry_client_api.py +++ b/src/karapace/sentry/sentry_client_api.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Mapping diff --git a/src/karapace/serialization.py b/src/karapace/serialization.py index 1c6d75d05..987fe6646 100644 --- a/src/karapace/serialization.py +++ b/src/karapace/serialization.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from aiohttp import BasicAuth diff --git a/src/karapace/statsd.py b/src/karapace/statsd.py index 3ef4d001c..4342ca29d 100644 --- a/src/karapace/statsd.py +++ b/src/karapace/statsd.py @@ -8,6 +8,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Iterator diff --git a/src/karapace/typing.py b/src/karapace/typing.py index 23791e471..9d30eaa34 100644 --- a/src/karapace/typing.py +++ b/src/karapace/typing.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from abc import ABC, abstractmethod diff --git a/src/karapace/utils.py b/src/karapace/utils.py index 10db7bfdb..22eb98182 100644 --- a/src/karapace/utils.py +++ b/src/karapace/utils.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from .typing import ArgJsonData, JsonData @@ -48,23 +49,19 @@ def _isoformat(datetime_obj: datetime) -> str: @overload -def default_json_serialization(obj: datetime) -> str: - ... +def default_json_serialization(obj: datetime) -> str: ... @overload -def default_json_serialization(obj: timedelta) -> float: - ... +def default_json_serialization(obj: timedelta) -> float: ... @overload -def default_json_serialization(obj: Decimal) -> str: - ... +def default_json_serialization(obj: Decimal) -> str: ... @overload -def default_json_serialization(obj: MappingProxyType) -> dict: - ... +def default_json_serialization(obj: MappingProxyType) -> dict: ... def default_json_serialization( @@ -89,8 +86,7 @@ def json_encode( sort_keys: bool | None = ..., compact: bool | None = ..., indent: int | None = ..., -) -> str: - ... +) -> str: ... @overload @@ -101,8 +97,7 @@ def json_encode( sort_keys: bool | None = ..., compact: bool | None = ..., indent: int | None = ..., -) -> bytes: - ... +) -> bytes: ... def json_encode( @@ -128,13 +123,11 @@ def json_encode( @overload -def json_decode(content: AnyStr | IO[AnyStr]) -> JsonData: - ... +def json_decode(content: AnyStr | IO[AnyStr]) -> JsonData: ... @overload -def json_decode(content: AnyStr | IO[AnyStr], assume_type: type[T]) -> T: - ... +def json_decode(content: AnyStr | IO[AnyStr], assume_type: type[T]) -> T: ... def json_decode( diff --git a/src/schema_registry/__main__.py b/src/schema_registry/__main__.py index f8b5684c6..b656ac001 100644 --- a/src/schema_registry/__main__.py +++ b/src/schema_registry/__main__.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from karapace.container import KarapaceContainer from schema_registry.container import SchemaRegistryContainer from schema_registry.factory import create_karapace_application, karapace_schema_registry_lifespan diff --git a/src/schema_registry/controller.py b/src/schema_registry/controller.py index 94c7d6540..fe658cd10 100644 --- a/src/schema_registry/controller.py +++ b/src/schema_registry/controller.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from avro.errors import SchemaParseException diff --git a/src/schema_registry/factory.py b/src/schema_registry/factory.py index b02c131c6..0cd970dc0 100644 --- a/src/schema_registry/factory.py +++ b/src/schema_registry/factory.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from collections.abc import AsyncGenerator, Callable from contextlib import asynccontextmanager from dependency_injector.wiring import inject, Provide diff --git a/src/schema_registry/messaging.py b/src/schema_registry/messaging.py index a5cdf0fc1..c4154bac4 100644 --- a/src/schema_registry/messaging.py +++ b/src/schema_registry/messaging.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from aiokafka.errors import MessageSizeTooLargeError from karapace.config import Config from karapace.errors import SchemaTooLargeException diff --git a/src/schema_registry/reader.py b/src/schema_registry/reader.py index 7525a0c95..6535729cb 100644 --- a/src/schema_registry/reader.py +++ b/src/schema_registry/reader.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from aiokafka.errors import ( diff --git a/src/schema_registry/registry.py b/src/schema_registry/registry.py index fe07e7d21..4d45f219d 100644 --- a/src/schema_registry/registry.py +++ b/src/schema_registry/registry.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from avro.compatibility import SchemaCompatibilityResult, SchemaCompatibilityType diff --git a/tests/conftest.py b/tests/conftest.py index 5b65c9405..6d54c4a6a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from avro.compatibility import SchemaCompatibilityResult from karapace.container import KarapaceContainer from pathlib import Path diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index 8e1d23d64..f99d8c71a 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from _pytest.fixtures import SubRequest diff --git a/tests/e2e/kafka/test_consumer.py b/tests/e2e/kafka/test_consumer.py index 84c69d76d..8f54c5d34 100644 --- a/tests/e2e/kafka/test_consumer.py +++ b/tests/e2e/kafka/test_consumer.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from aiokafka.errors import IllegalStateError, UnknownTopicOrPartitionError diff --git a/tests/e2e/schema_registry/test_jsonschema.py b/tests/e2e/schema_registry/test_jsonschema.py index 01267f6f0..759cee550 100644 --- a/tests/e2e/schema_registry/test_jsonschema.py +++ b/tests/e2e/schema_registry/test_jsonschema.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from jsonschema import Draft7Validator from karapace.client import Client from karapace.compatibility import CompatibilityModes diff --git a/tests/e2e/test_karapace.py b/tests/e2e/test_karapace.py index ccf4bde1e..32898f7b4 100644 --- a/tests/e2e/test_karapace.py +++ b/tests/e2e/test_karapace.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from collections.abc import Iterator from contextlib import closing, contextmanager, ExitStack from pathlib import Path diff --git a/tests/integration/backup/test_avro_export.py b/tests/integration/backup/test_avro_export.py index ac9adaa8a..e6cf85c69 100644 --- a/tests/integration/backup/test_avro_export.py +++ b/tests/integration/backup/test_avro_export.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.backup import api from karapace.backup.api import BackupVersion from karapace.client import Client diff --git a/tests/integration/backup/test_get_topic_configurations.py b/tests/integration/backup/test_get_topic_configurations.py index 688c21b67..302dd672d 100644 --- a/tests/integration/backup/test_get_topic_configurations.py +++ b/tests/integration/backup/test_get_topic_configurations.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from confluent_kafka.admin import NewTopic diff --git a/tests/integration/backup/test_legacy_backup.py b/tests/integration/backup/test_legacy_backup.py index a8fca6da6..caa358de1 100644 --- a/tests/integration/backup/test_legacy_backup.py +++ b/tests/integration/backup/test_legacy_backup.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from aiokafka.errors import InvalidTopicError from karapace.backup import api from karapace.backup.api import BackupVersion diff --git a/tests/integration/backup/test_session_timeout.py b/tests/integration/backup/test_session_timeout.py index b953b577b..82d85a2d5 100644 --- a/tests/integration/backup/test_session_timeout.py +++ b/tests/integration/backup/test_session_timeout.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from aiokafka.errors import NoBrokersAvailable from confluent_kafka.admin import NewTopic from karapace.backup.api import BackupVersion, create_backup diff --git a/tests/integration/backup/test_v3_backup.py b/tests/integration/backup/test_v3_backup.py index f03adc4ea..f7c2b8dee 100644 --- a/tests/integration/backup/test_v3_backup.py +++ b/tests/integration/backup/test_v3_backup.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from aiokafka.errors import InvalidReplicationFactorError, UnknownTopicOrPartitionError diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 39a0a3a3c..057546b8a 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from _pytest.fixtures import SubRequest diff --git a/tests/integration/test_client.py b/tests/integration/test_client.py index ba0fb5ff3..50d8d4570 100644 --- a/tests/integration/test_client.py +++ b/tests/integration/test_client.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.client import Client from karapace.schema_models import SchemaType, ValidatedTypedSchema from karapace.serialization import SchemaRegistryClient diff --git a/tests/integration/test_client_protobuf.py b/tests/integration/test_client_protobuf.py index 231730db9..ef2500ea9 100644 --- a/tests/integration/test_client_protobuf.py +++ b/tests/integration/test_client_protobuf.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.protobuf.kotlin_wrapper import trim_margin from karapace.schema_models import SchemaType, ValidatedTypedSchema from karapace.serialization import SchemaRegistryClient diff --git a/tests/integration/test_dependencies_compatibility_protobuf.py b/tests/integration/test_dependencies_compatibility_protobuf.py index dcbe64f86..87b2dd740 100644 --- a/tests/integration/test_dependencies_compatibility_protobuf.py +++ b/tests/integration/test_dependencies_compatibility_protobuf.py @@ -4,6 +4,7 @@ Copyright (c) 2019 Aiven Ltd See LICENSE for details """ + from karapace.client import Client from karapace.protobuf.kotlin_wrapper import trim_margin from tests.utils import create_subject_name_factory diff --git a/tests/integration/test_master_coordinator.py b/tests/integration/test_master_coordinator.py index 876a91d66..f3049be4c 100644 --- a/tests/integration/test_master_coordinator.py +++ b/tests/integration/test_master_coordinator.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.config import Config from karapace.coordinator.master_coordinator import MasterCoordinator from karapace.typing import SchemaReaderStoppper diff --git a/tests/integration/test_rest.py b/tests/integration/test_rest.py index ee504366b..035a9cf36 100644 --- a/tests/integration/test_rest.py +++ b/tests/integration/test_rest.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Mapping diff --git a/tests/integration/test_rest_consumer.py b/tests/integration/test_rest_consumer.py index f0003dbdd..c239db9e4 100644 --- a/tests/integration/test_rest_consumer.py +++ b/tests/integration/test_rest_consumer.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.kafka_rest_apis.consumer_manager import KNOWN_FORMATS from tests.utils import ( consumer_valid_payload, diff --git a/tests/integration/test_schema.py b/tests/integration/test_schema.py index 1a7937eca..e7f325e47 100644 --- a/tests/integration/test_schema.py +++ b/tests/integration/test_schema.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from attr import dataclass from http import HTTPStatus from karapace.client import Client diff --git a/tests/integration/test_schema_compatibility.py b/tests/integration/test_schema_compatibility.py index d9044a1a7..cf8c8fa01 100644 --- a/tests/integration/test_schema_compatibility.py +++ b/tests/integration/test_schema_compatibility.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Callable, Coroutine @@ -100,7 +101,8 @@ async def _register_baseline_schemas_with_incompatibilities_and_a_deleted_schema async def _register_no_baseline_schemas( - registry_async_client: Client, subject: Subject # pylint: disable=unused-argument + registry_async_client: Client, + subject: Subject, # pylint: disable=unused-argument ) -> None: pass diff --git a/tests/integration/test_schema_coordinator.py b/tests/integration/test_schema_coordinator.py index 81d106d6d..2d8e2bae7 100644 --- a/tests/integration/test_schema_coordinator.py +++ b/tests/integration/test_schema_coordinator.py @@ -6,6 +6,7 @@ Tests are adapted from aiokafka.tests.test_coordinator """ + from __future__ import annotations from aiokafka.client import AIOKafkaClient, ConnectionGroup, CoordinationType @@ -53,7 +54,8 @@ def fixture_mocked_aiokafka_client() -> Iterator[AIOKafkaClient]: @pytest.fixture(scope="function", name="coordinator") async def fixture_admin( - loop: asyncio.AbstractEventLoop, mocked_client: AIOKafkaClient # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, + mocked_client: AIOKafkaClient, # pylint: disable=unused-argument ) -> AsyncGenerator: coordinator = SchemaCoordinator( mocked_client, @@ -84,7 +86,8 @@ async def _get_client(kafka_servers: KafkaServers) -> AIOKafkaClient: @pytest.fixture(scope="function", name="client") async def get_client( - loop: asyncio.AbstractEventLoop, kafka_servers: KafkaServers # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, + kafka_servers: KafkaServers, # pylint: disable=unused-argument ) -> AsyncGenerator: client = await _get_client(kafka_servers) yield client diff --git a/tests/integration/test_schema_protobuf.py b/tests/integration/test_schema_protobuf.py index 5d0e55b7a..227cefda1 100644 --- a/tests/integration/test_schema_protobuf.py +++ b/tests/integration/test_schema_protobuf.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from dataclasses import dataclass diff --git a/tests/integration/test_schema_reader.py b/tests/integration/test_schema_reader.py index 0b5ae9f2c..578390d7e 100644 --- a/tests/integration/test_schema_reader.py +++ b/tests/integration/test_schema_reader.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from contextlib import closing from dataclasses import dataclass from karapace.config import Config diff --git a/tests/integration/test_schema_registry_auth.py b/tests/integration/test_schema_registry_auth.py index 89832355f..630074c02 100644 --- a/tests/integration/test_schema_registry_auth.py +++ b/tests/integration/test_schema_registry_auth.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.kafka.admin import KafkaAdminClient from karapace.schema_models import SchemaType, ValidatedTypedSchema from tests.integration.utils.rest_client import RetryRestClient diff --git a/tests/integration/test_schema_registry_mode.py b/tests/integration/test_schema_registry_mode.py index 86802c8b6..cf5a3de87 100644 --- a/tests/integration/test_schema_registry_mode.py +++ b/tests/integration/test_schema_registry_mode.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from karapace.client import Client from karapace.typing import Mode from tests.utils import create_schema_name_factory, create_subject_name_factory diff --git a/tests/integration/utils/cluster.py b/tests/integration/utils/cluster.py index e574cefa2..f2c7de2ff 100644 --- a/tests/integration/utils/cluster.py +++ b/tests/integration/utils/cluster.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import AsyncIterator diff --git a/tests/integration/utils/config.py b/tests/integration/utils/config.py index 63b7f5b48..ab4894d84 100644 --- a/tests/integration/utils/config.py +++ b/tests/integration/utils/config.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from dataclasses import dataclass from pathlib import Path diff --git a/tests/integration/utils/kafka_server.py b/tests/integration/utils/kafka_server.py index 520315b73..2a6a67082 100644 --- a/tests/integration/utils/kafka_server.py +++ b/tests/integration/utils/kafka_server.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from aiokafka.errors import AuthenticationFailedError, NoBrokersAvailable diff --git a/tests/integration/utils/network.py b/tests/integration/utils/network.py index 506751012..cb564efde 100644 --- a/tests/integration/utils/network.py +++ b/tests/integration/utils/network.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from collections.abc import Iterator from contextlib import closing, contextmanager diff --git a/tests/integration/utils/process.py b/tests/integration/utils/process.py index d1769f5e2..3d66f7825 100644 --- a/tests/integration/utils/process.py +++ b/tests/integration/utils/process.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.utils import Expiration from subprocess import Popen from tests.integration.utils.network import port_is_listening diff --git a/tests/integration/utils/rest_client.py b/tests/integration/utils/rest_client.py index 05539a34f..a7955c9cb 100644 --- a/tests/integration/utils/rest_client.py +++ b/tests/integration/utils/rest_client.py @@ -4,6 +4,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from aiohttp import BasicAuth diff --git a/tests/integration/utils/synchronization.py b/tests/integration/utils/synchronization.py index 8cc8db845..add96c56f 100644 --- a/tests/integration/utils/synchronization.py +++ b/tests/integration/utils/synchronization.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from pathlib import Path diff --git a/tests/integration/utils/zookeeper.py b/tests/integration/utils/zookeeper.py index 1ffb798db..e08d0fed5 100644 --- a/tests/integration/utils/zookeeper.py +++ b/tests/integration/utils/zookeeper.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from pathlib import Path from subprocess import Popen from tests.integration.utils.config import KafkaDescription, ZKConfig diff --git a/tests/schemas/json_schemas.py b/tests/schemas/json_schemas.py index ff90c1fa4..07a62e561 100644 --- a/tests/schemas/json_schemas.py +++ b/tests/schemas/json_schemas.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.schema_models import parse_jsonschema_definition # boolean schemas diff --git a/tests/schemas/protobuf.py b/tests/schemas/protobuf.py index afbb3f890..c6eb87126 100644 --- a/tests/schemas/protobuf.py +++ b/tests/schemas/protobuf.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + schema_protobuf_plain = """\ syntax = "proto3"; package com.codingharbour.protobuf; diff --git a/tests/unit/anonymize_schemas/test_anonymize_avro.py b/tests/unit/anonymize_schemas/test_anonymize_avro.py index fbd51563b..1e69bbddc 100644 --- a/tests/unit/anonymize_schemas/test_anonymize_avro.py +++ b/tests/unit/anonymize_schemas/test_anonymize_avro.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.anonymize_schemas.anonymize_avro import anonymize import json diff --git a/tests/unit/avro_dataclasses/test_introspect.py b/tests/unit/avro_dataclasses/test_introspect.py index 79a9e503d..04ad0f3a5 100644 --- a/tests/unit/avro_dataclasses/test_introspect.py +++ b/tests/unit/avro_dataclasses/test_introspect.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from collections.abc import Mapping, Sequence from dataclasses import dataclass, Field, field, fields from enum import Enum diff --git a/tests/unit/avro_dataclasses/test_models.py b/tests/unit/avro_dataclasses/test_models.py index cba32b08c..24db32158 100644 --- a/tests/unit/avro_dataclasses/test_models.py +++ b/tests/unit/avro_dataclasses/test_models.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from dataclasses import dataclass, field from karapace.avro_dataclasses.models import AvroModel diff --git a/tests/unit/backup/backends/test_v1.py b/tests/unit/backup/backends/test_v1.py index 205acd25b..815562752 100644 --- a/tests/unit/backup/backends/test_v1.py +++ b/tests/unit/backup/backends/test_v1.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from functools import partial from karapace.backup.backends.reader import ProducerSend, RestoreTopicLegacy from karapace.backup.backends.v1 import SchemaBackupV1Reader diff --git a/tests/unit/backup/backends/test_v2.py b/tests/unit/backup/backends/test_v2.py index b2ad273b2..b525f30e7 100644 --- a/tests/unit/backup/backends/test_v2.py +++ b/tests/unit/backup/backends/test_v2.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from functools import partial diff --git a/tests/unit/backup/backends/v3/conftest.py b/tests/unit/backup/backends/v3/conftest.py index 412a3f2ac..62219a5b1 100644 --- a/tests/unit/backup/backends/v3/conftest.py +++ b/tests/unit/backup/backends/v3/conftest.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from collections.abc import Iterator from contextlib import closing diff --git a/tests/unit/backup/backends/v3/test_backend.py b/tests/unit/backup/backends/v3/test_backend.py index 7ea6811f7..0ffad9fb5 100644 --- a/tests/unit/backup/backends/v3/test_backend.py +++ b/tests/unit/backup/backends/v3/test_backend.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from dataclasses import replace from karapace.backup.backends.reader import ProducerSend, RestoreTopic from karapace.backup.backends.v3.backend import _PartitionStats, SchemaBackupV3Reader, SchemaBackupV3Writer diff --git a/tests/unit/backup/backends/v3/test_serialisation.py b/tests/unit/backup/backends/v3/test_serialisation.py index fe8872911..9bddee6b1 100644 --- a/tests/unit/backup/backends/v3/test_serialisation.py +++ b/tests/unit/backup/backends/v3/test_serialisation.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from hypothesis import given from hypothesis.strategies import integers from karapace.backup.backends.v3.errors import ( diff --git a/tests/unit/backup/test_api.py b/tests/unit/backup/test_api.py index bc8f15f7e..474dd6fd8 100644 --- a/tests/unit/backup/test_api.py +++ b/tests/unit/backup/test_api.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from aiokafka.errors import KafkaError, TopicAlreadyExistsError diff --git a/tests/unit/backup/test_encoders.py b/tests/unit/backup/test_encoders.py index 8abb54da6..83d84cffc 100644 --- a/tests/unit/backup/test_encoders.py +++ b/tests/unit/backup/test_encoders.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from karapace.backup.encoders import encode_key, encode_value diff --git a/tests/unit/backup/test_poll_timeout.py b/tests/unit/backup/test_poll_timeout.py index 62660a3b2..3ce63d009 100644 --- a/tests/unit/backup/test_poll_timeout.py +++ b/tests/unit/backup/test_poll_timeout.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from datetime import timedelta from karapace.backup.poll_timeout import PollTimeout diff --git a/tests/unit/backup/test_safe_writer.py b/tests/unit/backup/test_safe_writer.py index c881498c1..3e4e29203 100644 --- a/tests/unit/backup/test_safe_writer.py +++ b/tests/unit/backup/test_safe_writer.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.backup.safe_writer import ( _check_destination_file, bytes_writer, diff --git a/tests/unit/compatibility/jsonschema/test_jsonschema_compatibility.py b/tests/unit/compatibility/jsonschema/test_jsonschema_compatibility.py index ae8da309f..c7b64fd0e 100644 --- a/tests/unit/compatibility/jsonschema/test_jsonschema_compatibility.py +++ b/tests/unit/compatibility/jsonschema/test_jsonschema_compatibility.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from avro.compatibility import SchemaCompatibilityResult, SchemaCompatibilityType from jsonschema import Draft7Validator from karapace.compatibility.jsonschema.checks import compatibility diff --git a/tests/unit/compatibility/test_compatibility.py b/tests/unit/compatibility/test_compatibility.py index af41aae99..a4195be99 100644 --- a/tests/unit/compatibility/test_compatibility.py +++ b/tests/unit/compatibility/test_compatibility.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from avro.compatibility import SchemaCompatibilityType from karapace.compatibility import CompatibilityModes from karapace.compatibility.schema_compatibility import SchemaCompatibility diff --git a/tests/unit/protobuf/test_compare_elements.py b/tests/unit/protobuf/test_compare_elements.py index 64389f11d..750f4517f 100644 --- a/tests/unit/protobuf/test_compare_elements.py +++ b/tests/unit/protobuf/test_compare_elements.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.protobuf.compare_result import CompareResult, Modification from karapace.protobuf.compare_type_storage import CompareTypes from karapace.protobuf.field import Field diff --git a/tests/unit/protobuf/test_dependency.py b/tests/unit/protobuf/test_dependency.py index bc542b93c..1c2682505 100644 --- a/tests/unit/protobuf/test_dependency.py +++ b/tests/unit/protobuf/test_dependency.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.protobuf.kotlin_wrapper import trim_margin from karapace.protobuf.schema import ProtobufSchema diff --git a/tests/unit/protobuf/test_io.py b/tests/unit/protobuf/test_io.py index 61e26d075..2cc8b5827 100644 --- a/tests/unit/protobuf/test_io.py +++ b/tests/unit/protobuf/test_io.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.dependency import Dependency from karapace.protobuf.io import crawl_dependencies from karapace.protobuf.schema import ProtobufSchema diff --git a/tests/unit/protobuf/test_proto_file_element.py b/tests/unit/protobuf/test_proto_file_element.py index fb4a63e9b..88ccc8efd 100644 --- a/tests/unit/protobuf/test_proto_file_element.py +++ b/tests/unit/protobuf/test_proto_file_element.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + # Ported from square/wire: # wire-library/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoFileElementTest.kt from karapace.protobuf.extend_element import ExtendElement diff --git a/tests/unit/protobuf/test_proto_parser.py b/tests/unit/protobuf/test_proto_parser.py index 316276796..c91688e95 100644 --- a/tests/unit/protobuf/test_proto_parser.py +++ b/tests/unit/protobuf/test_proto_parser.py @@ -1381,7 +1381,7 @@ def test_default_field_with_string_escapes(): OptionElement( "x", OptionElement.Kind.STRING, - "\u0007\b\u000C\n\r\t\u000b\u0001f\u0001\u0001\u0009\u0009I\u000e\u000e\u000e\u000eAA", + "\u0007\b\u000c\n\r\t\u000b\u0001f\u0001\u0001\u0009\u0009I\u000e\u000e\u000e\u000eAA", ) ], ) @@ -1390,7 +1390,7 @@ def test_default_field_with_string_escapes(): OptionElement( "x", OptionElement.Kind.STRING, - "\u0007\b\u000C\n\r\t\u000b\u0001f\u0001\u0001\u0009\u0009I\u000e\u000e\u000e\u000eAA", + "\u0007\b\u000c\n\r\t\u000b\u0001f\u0001\u0001\u0009\u0009I\u000e\u000e\u000e\u000eAA", ) in field.options ) @@ -1834,7 +1834,7 @@ def test_option_numerical_bounds(): OptionElement( "x", OptionElement.Kind.STRING, - "çok\u0007\b\u000C\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011" + "çok\u0007\b\u000c\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011" "\u0001\u0001\u0011güzel", ) ], @@ -1849,7 +1849,7 @@ def test_option_numerical_bounds(): OptionElement( "x", OptionElement.Kind.STRING, - "çok\u0007\b\u000C\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011" + "çok\u0007\b\u000c\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011" "\u0001\u0001\u0011güzel", ) ], diff --git a/tests/unit/protobuf/test_protobuf_compatibility.py b/tests/unit/protobuf/test_protobuf_compatibility.py index eaf9b98a5..b0c000d26 100644 --- a/tests/unit/protobuf/test_protobuf_compatibility.py +++ b/tests/unit/protobuf/test_protobuf_compatibility.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.protobuf.compare_result import CompareResult, Modification from karapace.protobuf.kotlin_wrapper import trim_margin from karapace.protobuf.location import Location diff --git a/tests/unit/protobuf/test_protobuf_schema.py b/tests/unit/protobuf/test_protobuf_schema.py index 9b89a1425..733ff3d0e 100644 --- a/tests/unit/protobuf/test_protobuf_schema.py +++ b/tests/unit/protobuf/test_protobuf_schema.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.dependency import Dependency from karapace.protobuf.compare_result import CompareResult from karapace.protobuf.kotlin_wrapper import trim_margin diff --git a/tests/unit/protobuf/test_protobuf_schema_name.py b/tests/unit/protobuf/test_protobuf_schema_name.py index bcbca9fd0..691f295c1 100644 --- a/tests/unit/protobuf/test_protobuf_schema_name.py +++ b/tests/unit/protobuf/test_protobuf_schema_name.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.protobuf.schema import ProtobufSchema from karapace.schema_models import ValidatedTypedSchema from karapace.schema_type import SchemaType diff --git a/tests/unit/protobuf/test_protoc.py b/tests/unit/protobuf/test_protoc.py index d61648d9e..9b12499cc 100644 --- a/tests/unit/protobuf/test_protoc.py +++ b/tests/unit/protobuf/test_protoc.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.container import KarapaceContainer from karapace.protobuf.io import calculate_class_name from karapace.protobuf.kotlin_wrapper import trim_margin diff --git a/tests/unit/schema_registry/test_controller.py b/tests/unit/schema_registry/test_controller.py index 4c4b0b16d..e07f45fff 100644 --- a/tests/unit/schema_registry/test_controller.py +++ b/tests/unit/schema_registry/test_controller.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from fastapi.exceptions import HTTPException from karapace.rapu import HTTPResponse from karapace.schema_models import SchemaType, ValidatedTypedSchema diff --git a/tests/unit/test_auth.py b/tests/unit/test_auth.py index 24786023d..c3916b4f1 100644 --- a/tests/unit/test_auth.py +++ b/tests/unit/test_auth.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from karapace.auth import ACLAuthorizer, ACLEntry, hash_password, HashAlgorithm, Operation, User import re diff --git a/tests/unit/test_authentication.py b/tests/unit/test_authentication.py index 9834865fb..a3d0cf268 100644 --- a/tests/unit/test_authentication.py +++ b/tests/unit/test_authentication.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections.abc import Mapping diff --git a/tests/unit/test_avro_compatibility.py b/tests/unit/test_avro_compatibility.py index 47c005f22..288fbeda5 100644 --- a/tests/unit/test_avro_compatibility.py +++ b/tests/unit/test_avro_compatibility.py @@ -5,6 +5,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from avro.compatibility import ReaderWriterCompatibilityChecker, SchemaCompatibilityResult, SchemaCompatibilityType from avro.name import Names from avro.schema import ArraySchema, Field, MapSchema, Schema, UnionSchema diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 79ce7da78..d1fa63204 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -4,6 +4,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.constants import DEFAULT_AIOHTTP_CLIENT_MAX_SIZE, DEFAULT_PRODUCER_MAX_REQUEST from karapace.container import KarapaceContainer diff --git a/tests/unit/test_features.py b/tests/unit/test_features.py index bb2b708c2..708a2bbce 100644 --- a/tests/unit/test_features.py +++ b/tests/unit/test_features.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + import aiokafka.codec diff --git a/tests/unit/test_forwarding_client.py b/tests/unit/test_forwarding_client.py index 6dc9700c9..34df7869f 100644 --- a/tests/unit/test_forwarding_client.py +++ b/tests/unit/test_forwarding_client.py @@ -4,6 +4,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from dataclasses import dataclass diff --git a/tests/unit/test_in_memory_database.py b/tests/unit/test_in_memory_database.py index 9dc8edf88..64e9b9649 100644 --- a/tests/unit/test_in_memory_database.py +++ b/tests/unit/test_in_memory_database.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from collections import defaultdict diff --git a/tests/unit/test_kafka_error_handler.py b/tests/unit/test_kafka_error_handler.py index 183205137..bf3653bbe 100644 --- a/tests/unit/test_kafka_error_handler.py +++ b/tests/unit/test_kafka_error_handler.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from _pytest.logging import LogCaptureFixture from karapace.container import KarapaceContainer from karapace.errors import CorruptKafkaRecordException diff --git a/tests/unit/test_protobuf_binary_serialization.py b/tests/unit/test_protobuf_binary_serialization.py index 99bfe375e..aa28896d4 100644 --- a/tests/unit/test_protobuf_binary_serialization.py +++ b/tests/unit/test_protobuf_binary_serialization.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.protobuf.schema import ProtobufSchema from karapace.protobuf.serialization import deserialize, serialize from tests.schemas.protobuf import ( diff --git a/tests/unit/test_protobuf_serialization.py b/tests/unit/test_protobuf_serialization.py index 1cb013538..49af470e1 100644 --- a/tests/unit/test_protobuf_serialization.py +++ b/tests/unit/test_protobuf_serialization.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.container import KarapaceContainer from karapace.dependency import Dependency from karapace.protobuf.kotlin_wrapper import trim_margin diff --git a/tests/unit/test_rapu.py b/tests/unit/test_rapu.py index ba5c77e8c..b965dc09b 100644 --- a/tests/unit/test_rapu.py +++ b/tests/unit/test_rapu.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from _pytest.logging import LogCaptureFixture from aiohttp.client_exceptions import ClientConnectionError from aiohttp.web import Request diff --git a/tests/unit/test_rest_auth.py b/tests/unit/test_rest_auth.py index ad2d54057..aa7bd41b6 100644 --- a/tests/unit/test_rest_auth.py +++ b/tests/unit/test_rest_auth.py @@ -3,6 +3,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from __future__ import annotations from karapace.container import KarapaceContainer diff --git a/tests/unit/test_serialization.py b/tests/unit/test_serialization.py index 041df44ab..c96ef7bef 100644 --- a/tests/unit/test_serialization.py +++ b/tests/unit/test_serialization.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from karapace.container import KarapaceContainer from karapace.schema_models import SchemaType, ValidatedTypedSchema, Versioner from karapace.serialization import ( diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 9a3a33d73..02c7f6f9a 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -2,6 +2,7 @@ Copyright (c) 2024 Aiven Ltd See LICENSE for details """ + from _pytest.logging import LogCaptureFixture from karapace.utils import shutdown from unittest.mock import patch diff --git a/tests/utils.py b/tests/utils.py index 940f9fe65..634b77e6f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -2,6 +2,7 @@ Copyright (c) 2023 Aiven Ltd See LICENSE for details """ + from aiohttp.client_exceptions import ClientOSError, ServerDisconnectedError from aiokafka.errors import TopicAlreadyExistsError from collections.abc import Callable From 40ace39ad8803a84aae2ffc3b386b3d01c1f59d0 Mon Sep 17 00:00:00 2001 From: Jarkko Jaakola Date: Wed, 8 Jan 2025 12:34:34 +0200 Subject: [PATCH 3/3] chore: remove pylint --- .pre-commit-config.yaml | 7 - .pylintrc | 43 ------ container/compose.yml | 3 - .../anonymize_schemas/anonymize_avro.py | 2 +- src/karapace/auth.py | 5 +- src/karapace/avro_dataclasses/introspect.py | 2 +- src/karapace/avro_dataclasses/models.py | 2 - src/karapace/backup/api.py | 2 +- src/karapace/backup/backends/writer.py | 2 - src/karapace/backup/cli.py | 2 +- .../compatibility/jsonschema/checks.py | 2 +- .../compatibility/jsonschema/utils.py | 2 +- .../coordinator/schema_coordinator.py | 2 +- src/karapace/kafka/common.py | 17 +-- src/karapace/karapace_all.py | 2 +- src/karapace/protobuf/encoding_variants.py | 2 +- src/karapace/protobuf/io.py | 7 +- src/karapace/protobuf/known_dependency.py | 2 +- src/karapace/protobuf/message_element.py | 2 +- src/karapace/protobuf/proto_parser.py | 5 +- src/karapace/protobuf/proto_type.py | 2 +- src/karapace/protobuf/protobuf_to_dict.py | 7 +- src/karapace/protobuf/syntax_reader.py | 1 - src/karapace/rapu.py | 20 +-- src/karapace/sentry/sentry_client.py | 2 +- src/karapace/serialization.py | 6 +- src/karapace/statsd.py | 2 +- src/karapace/utils.py | 12 +- src/schema_registry/controller.py | 2 +- src/schema_registry/middlewares/__init__.py | 2 +- src/schema_registry/reader.py | 14 +- .../routers/master_availability.py | 4 +- tests/conftest.py | 2 +- tests/e2e/conftest.py | 4 +- tests/integration/backup/test_v3_backup.py | 2 +- tests/integration/conftest.py | 34 ++--- .../integration/test_schema_compatibility.py | 2 +- tests/integration/test_schema_coordinator.py | 124 +++++++++--------- tests/integration/test_schema_reader.py | 6 +- tests/integration/utils/kafka_server.py | 2 +- tests/integration/utils/zookeeper.py | 2 +- .../anonymize_schemas/test_anonymize_avro.py | 2 - tests/unit/backup/backends/test_v2.py | 4 +- tests/unit/backup/backends/v3/test_backend.py | 2 +- tests/unit/instrumentation/test_prometheus.py | 2 +- .../test_rest_proxy_cluster_metadata_cache.py | 1 - tests/unit/schema_registry/test_controller.py | 6 +- tests/unit/schema_registry/test_reader.py | 8 +- tests/unit/test_avro_compatibility.py | 3 +- tests/unit/test_forwarding_client.py | 8 +- tests/unit/test_rapu.py | 2 +- tests/unit/test_rest_auth.py | 1 - website/source/conf.py | 2 +- 53 files changed, 160 insertions(+), 246 deletions(-) delete mode 100644 .pylintrc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cfcb550bf..18ba14208 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,13 +40,6 @@ repos: # https://github.com/hadolint/hadolint/issues/497 - --ignore=DL3042 -- repo: https://github.com/PyCQA/pylint - # Note: pre-commit autoupdate changes to an alpha version. Instead, manually find the - # latest stable version here: https://github.com/pylint-dev/pylint/releases - rev: v3.2.6 - hooks: - - id: pylint - - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: v0.8.6 diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index e2c2f6242..000000000 --- a/.pylintrc +++ /dev/null @@ -1,43 +0,0 @@ -[MASTER] -jobs=4 -init-hook='import sys; sys.path.append(".")' - -[MESSAGES CONTROL] -enable= - useless-suppression, - -disable= - duplicate-code, - fixme, - import-outside-toplevel, - invalid-field-call, - invalid-name, - missing-docstring, - too-few-public-methods, - too-many-arguments, - too-many-branches, - too-many-instance-attributes, - too-many-lines, - too-many-locals, - too-many-nested-blocks, - too-many-public-methods, - too-many-statements, - wrong-import-order, - import-error, - consider-using-f-string, - use-implicit-booleaness-not-comparison, - unspecified-encoding, - no-name-in-module, - use-list-literal, - use-dict-literal, - no-value-for-parameter, - relative-beyond-top-level, - - -[FORMAT] -max-line-length=125 - -[REPORTS] -output-format=text -reports=no -score=no diff --git a/container/compose.yml b/container/compose.yml index 263685e2f..f50268096 100644 --- a/container/compose.yml +++ b/container/compose.yml @@ -143,10 +143,7 @@ services: - ../tests:/opt/karapace/tests - ../pytest.ini:/opt/karapace/pytest.ini - ../mypy.ini:/opt/karapace/mypy.ini - - ../.flake8:/opt/karapace/.flake8 - - ../.isort.cfg:/opt/karapace/.isort.cfg - ../.pre-commit-config.yaml:/opt/karapace/.pre-commit-config.yaml - - ../.pylintrc:/opt/karapace/.pylintrc - ../.coveragerc:/opt/karapace/.coveragerc - ../.coverage.3.10:/opt/karapace/coverage/.coverage.3.10 - ../.coverage.3.11:/opt/karapace/coverage/.coverage.3.11 diff --git a/src/karapace/anonymize_schemas/anonymize_avro.py b/src/karapace/anonymize_schemas/anonymize_avro.py index 79d3f5d1a..701fca858 100644 --- a/src/karapace/anonymize_schemas/anonymize_avro.py +++ b/src/karapace/anonymize_schemas/anonymize_avro.py @@ -99,7 +99,7 @@ def anonymize_element(m: re.Match) -> str: def anonymize(input_schema: Schema) -> Schema: - if not input_schema: # pylint: disable=no-else-return + if not input_schema: return input_schema elif isinstance(input_schema, str): if input_schema in ALL_TYPES: diff --git a/src/karapace/auth.py b/src/karapace/auth.py index 9c2a34218..1342aa5b8 100644 --- a/src/karapace/auth.py +++ b/src/karapace/auth.py @@ -115,8 +115,7 @@ class AuthenticatorAndAuthorizer(AuthenticateProtocol, AuthorizeProtocol): async def close(self) -> None: ... - async def start(self, stats: StatsClient) -> None: # pylint: disable=unused-argument - ... + async def start(self, stats: StatsClient) -> None: ... class NoAuthAndAuthz(AuthenticatorAndAuthorizer): @@ -237,7 +236,7 @@ async def _refresh_authfile() -> None: except asyncio.CancelledError: log.info("Closing schema registry ACL refresh task") return - except Exception as ex: # pylint: disable=broad-except + except Exception as ex: log.exception("Schema registry auth file could not be loaded") stats.unexpected_exception(ex=ex, where="schema_registry_authfile_reloader") return diff --git a/src/karapace/avro_dataclasses/introspect.py b/src/karapace/avro_dataclasses/introspect.py index 9eb4ec85f..34b7dbd15 100644 --- a/src/karapace/avro_dataclasses/introspect.py +++ b/src/karapace/avro_dataclasses/introspect.py @@ -57,7 +57,7 @@ def _field_type_array(field: Field, origin: type, type_: object) -> AvroType: sequence_types: Final = frozenset({tuple, list, Sequence}) -def _field_type(field: Field, type_: object) -> AvroType: # pylint: disable=too-many-return-statements +def _field_type(field: Field, type_: object) -> AvroType: # Handle primitives. if type_ is bool: return "boolean" diff --git a/src/karapace/avro_dataclasses/models.py b/src/karapace/avro_dataclasses/models.py index 719871920..720657d7b 100644 --- a/src/karapace/avro_dataclasses/models.py +++ b/src/karapace/avro_dataclasses/models.py @@ -76,8 +76,6 @@ def parse(value: object) -> object: def from_avro_value(type_: object) -> Parser | None: - # pylint: disable=too-many-return-statements - if isinstance(type_, type): if is_dataclass(type_): return partial(from_avro_dict, type_) diff --git a/src/karapace/backup/api.py b/src/karapace/backup/api.py index 7f74d7cb8..e52ccfc54 100644 --- a/src/karapace/backup/api.py +++ b/src/karapace/backup/api.py @@ -171,7 +171,7 @@ def before_sleep(it: RetryCallState) -> None: result = f"failed ({outcome.exception()})" else: result = f"returned {outcome.result()!r}" - LOG.info(f"{description} {result}, retrying... (Ctrl+C to abort)") # pylint: disable=logging-fstring-interpolation + LOG.info(f"{description} {result}, retrying... (Ctrl+C to abort)") return before_sleep diff --git a/src/karapace/backup/backends/writer.py b/src/karapace/backup/backends/writer.py index 78dd330e3..281b20c89 100644 --- a/src/karapace/backup/backends/writer.py +++ b/src/karapace/backup/backends/writer.py @@ -32,8 +32,6 @@ def _noop_context(path: T) -> Iterator[T]: class BackupWriter(Generic[B, F], abc.ABC): """Common interface and base class for all backup writer backends.""" - # pylint: disable=unused-argument - P = TypeVar("P", bound="StdOut | Path") def prepare_location( diff --git a/src/karapace/backup/cli.py b/src/karapace/backup/cli.py index 0f172da8e..47c9290ec 100644 --- a/src/karapace/backup/cli.py +++ b/src/karapace/backup/cli.py @@ -165,7 +165,7 @@ def main() -> None: # TODO: This specific treatment of StaleConsumerError looks quite misplaced # here, and should probably be pushed down into the (internal) API layer. except StaleConsumerError as e: - logger.error( # pylint: disable=logging-fstring-interpolation + logger.error( f"The Kafka consumer did not receive any records for partition {e.topic_partition.partition} of topic " f"{e.topic_partition.topic!r} " f"within the poll timeout ({e.poll_timeout} seconds) while trying to reach offset {e.end_offset:,} " diff --git a/src/karapace/compatibility/jsonschema/checks.py b/src/karapace/compatibility/jsonschema/checks.py index 582c7e8e1..81afd2ec7 100644 --- a/src/karapace/compatibility/jsonschema/checks.py +++ b/src/karapace/compatibility/jsonschema/checks.py @@ -834,7 +834,7 @@ def compatibility_subschemas( location: list[str], ) -> SchemaCompatibilityResult: # https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.10 - # pylint: disable=too-many-return-statements + reader_subschemas_and_type = maybe_get_subschemas_and_type(reader_schema) writer_subschemas_and_type = maybe_get_subschemas_and_type(writer_schema) diff --git a/src/karapace/compatibility/jsonschema/utils.py b/src/karapace/compatibility/jsonschema/utils.py index fe1f1f467..2feae5925 100644 --- a/src/karapace/compatibility/jsonschema/utils.py +++ b/src/karapace/compatibility/jsonschema/utils.py @@ -258,7 +258,7 @@ def gt(left: int | None, right: int | None) -> bool: def lt(left: int | None, right: int | None) -> bool: - return gt(right, left) # pylint: disable=arguments-out-of-order + return gt(right, left) def ne(writer: T | None, reader: T | None) -> bool: diff --git a/src/karapace/coordinator/schema_coordinator.py b/src/karapace/coordinator/schema_coordinator.py index a7624380a..e699c0c82 100644 --- a/src/karapace/coordinator/schema_coordinator.py +++ b/src/karapace/coordinator/schema_coordinator.py @@ -583,7 +583,7 @@ async def ensure_coordinator_known(self) -> None: async def _coordination_routine(self) -> None: try: await self.__coordination_routine() - except asyncio.CancelledError: # pylint: disable=try-except-raise + except asyncio.CancelledError: raise except Exception as exc: LOG.error("Unexpected error in coordinator routine", exc_info=True) diff --git a/src/karapace/kafka/common.py b/src/karapace/kafka/common.py index fd5441d16..6662d2678 100644 --- a/src/karapace/kafka/common.py +++ b/src/karapace/kafka/common.py @@ -50,16 +50,16 @@ def translate_from_kafkaerror(error: KafkaError) -> Exception: """ code = error.code() if code in ( - KafkaError._NOENT, # pylint: disable=protected-access - KafkaError._UNKNOWN_PARTITION, # pylint: disable=protected-access - KafkaError._UNKNOWN_TOPIC, # pylint: disable=protected-access + KafkaError._NOENT, + KafkaError._UNKNOWN_PARTITION, + KafkaError._UNKNOWN_TOPIC, ): return UnknownTopicOrPartitionError() - if code == KafkaError._TIMED_OUT: # pylint: disable=protected-access + if code == KafkaError._TIMED_OUT: return KafkaTimeoutError() - if code == KafkaError._STATE: # pylint: disable=protected-access + if code == KafkaError._STATE: return IllegalStateError() - if code == KafkaError._RESOLVE: # pylint: disable=protected-access + if code == KafkaError._RESOLVE: return KafkaUnavailableError() return for_code(code) @@ -207,10 +207,7 @@ def _verify_connection(self) -> None: # to the callback function defined in the `error_cb` config self._activate_callbacks() self.log.info("Could not establish connection due to errors: %s", self._errors) - if any( - error.code() == KafkaError._AUTHENTICATION - for error in self._errors # pylint: disable=protected-access - ): + if any(error.code() == KafkaError._AUTHENTICATION for error in self._errors): raise AuthenticationFailedError() from exc continue else: diff --git a/src/karapace/karapace_all.py b/src/karapace/karapace_all.py index 3f243688a..0c9acf253 100644 --- a/src/karapace/karapace_all.py +++ b/src/karapace/karapace_all.py @@ -35,7 +35,7 @@ def main( try: prometheus.setup_metrics(app=app) app.run() # `close` will be called by the callback `close_by_app` set by `KarapaceBase` - except Exception as ex: # pylint: disable-broad-except + except Exception as ex: app.stats.unexpected_exception(ex=ex, where="karapace") raise return 0 diff --git a/src/karapace/protobuf/encoding_variants.py b/src/karapace/protobuf/encoding_variants.py index ba1e24232..736e02c99 100644 --- a/src/karapace/protobuf/encoding_variants.py +++ b/src/karapace/protobuf/encoding_variants.py @@ -37,7 +37,7 @@ def read_indexes(bio: BytesIO) -> list[int]: size: int = read_varint(bio) except EOFError: # TODO: change exception - # pylint: disable=raise-missing-from + raise IllegalArgumentException("problem with reading binary data") if size == 0: return [0] diff --git a/src/karapace/protobuf/io.py b/src/karapace/protobuf/io.py index ee22dacc1..1c0385001 100644 --- a/src/karapace/protobuf/io.py +++ b/src/karapace/protobuf/io.py @@ -43,7 +43,6 @@ def find_message_name(schema: ProtobufSchema, indexes: Iterable[int]) -> str: try: message = types[index] except IndexError: - # pylint: disable=raise-missing-from raise IllegalArgumentException(f"Invalid message indexes: {indexes}") if message and isinstance(message, MessageElement): @@ -185,7 +184,7 @@ def reader_process( reader_queue.put(protobuf_to_dict(read_data(config, writer_schema, reader_schema, bio), True)) # Reading happens in the forked process, catch is broad so exception will get communicated # back to calling process. - except BaseException as base_exception: # pylint: disable=broad-except + except BaseException as base_exception: reader_queue.put(base_exception) @@ -260,13 +259,13 @@ def writer_process( writer_queue.put(result) # Writing happens in the forked process, catch is broad so exception will get communicated # back to calling process. - except Exception as bare_exception: # pylint: disable=broad-exception-caught + except Exception as bare_exception: try: raise ProtobufTypeException(writer_schema, datum) from bare_exception except ProtobufTypeException as protobuf_exception: writer_queue.put(protobuf_exception) raise protobuf_exception - except BaseException as base_exception: # pylint: disable=broad-exception-caught + except BaseException as base_exception: writer_queue.put(base_exception) diff --git a/src/karapace/protobuf/known_dependency.py b/src/karapace/protobuf/known_dependency.py index bb250707b..a42576d52 100644 --- a/src/karapace/protobuf/known_dependency.py +++ b/src/karapace/protobuf/known_dependency.py @@ -16,7 +16,7 @@ def static_init(cls: Any) -> object: return cls -@static_init # pylint: disable=used-before-assignment +@static_init class KnownDependency: index: dict = dict() index_simple: dict = dict() diff --git a/src/karapace/protobuf/message_element.py b/src/karapace/protobuf/message_element.py index 79538231d..1f516ba6e 100644 --- a/src/karapace/protobuf/message_element.py +++ b/src/karapace/protobuf/message_element.py @@ -92,7 +92,7 @@ def to_schema(self) -> str: return "".join(result) def compare(self, other: TypeElement, result: CompareResult, types: CompareTypes) -> None: - from karapace.protobuf.compare_type_lists import compare_type_lists # pylint: disable=cyclic-import + from karapace.protobuf.compare_type_lists import compare_type_lists if not isinstance(other, MessageElement): result.add_modification(Modification.TYPE_ALTER) diff --git a/src/karapace/protobuf/proto_parser.py b/src/karapace/protobuf/proto_parser.py index 11e5fdf63..63f2c4f2c 100644 --- a/src/karapace/protobuf/proto_parser.py +++ b/src/karapace/protobuf/proto_parser.py @@ -169,7 +169,6 @@ def read_declaration( | GroupElement | FieldElement ) = None - # pylint no-else-return if label == "package" and context.permits_package(): self.package_name = self.reader.read_name() self.prefix = f"{self.package_name}." @@ -504,7 +503,7 @@ def read_reserved(self, location: Location, documentation: str) -> ReservedEleme values.append(KotlinRange(tag_start, tag_end)) ch = self.reader.read_char() - # pylint: disable=no-else-break + if ch == ";": break elif ch == ",": @@ -543,7 +542,7 @@ def read_extensions(self, location: Location, documentation: str) -> ExtensionsE values.append(KotlinRange(start, end)) ch = self.reader.read_char() - # pylint: disable=no-else-break + if ch == ";": break elif ch == ",": diff --git a/src/karapace/protobuf/proto_type.py b/src/karapace/protobuf/proto_type.py index 154cc18e7..a41d955f0 100644 --- a/src/karapace/protobuf/proto_type.py +++ b/src/karapace/protobuf/proto_type.py @@ -20,7 +20,7 @@ def static_init(cls) -> object: return cls -@static_init # pylint: disable=used-before-assignment +@static_init class ProtoType: @property def simple_name(self) -> str: diff --git a/src/karapace/protobuf/protobuf_to_dict.py b/src/karapace/protobuf/protobuf_to_dict.py index 8d2845f3a..20d11a891 100644 --- a/src/karapace/protobuf/protobuf_to_dict.py +++ b/src/karapace/protobuf/protobuf_to_dict.py @@ -33,8 +33,6 @@ def timestamp_to_datetime(ts): return dt -# pylint: enable=no-member - EXTENSION_CONTAINER = "___X" TYPE_CALLABLE_MAP = MappingProxyType( @@ -209,14 +207,12 @@ def _get_field_mapping(pb, dict_value, strict): try: ext_num = int(ext_num) except ValueError: - # pylint: disable=raise-missing-from raise ValueError("Extension keys must be integers.") - # pylint: disable=protected-access + if ext_num not in pb._extensions_by_number: if strict: raise KeyError(f"{pb} does not have a extension with number {key}. Perhaps you forgot to import it?") continue - # pylint: disable=protected-access ext_field = pb._extensions_by_number[ext_num] # noinspection PyUnusedLocal @@ -310,7 +306,6 @@ def _string_to_enum(field, input_value, strict=False): input_value = field.enum_type.values_by_name[input_value].number except KeyError: if strict: - # pylint: disable=raise-missing-from raise KeyError(f"`{input_value}` is not a valid value for field `{field.name}`") return _string_to_enum(field, input_value.upper(), strict=True) return input_value diff --git a/src/karapace/protobuf/syntax_reader.py b/src/karapace/protobuf/syntax_reader.py index 99ecaba79..8d5897c2d 100644 --- a/src/karapace/protobuf/syntax_reader.py +++ b/src/karapace/protobuf/syntax_reader.py @@ -224,7 +224,6 @@ def read_comment(self) -> str: buffer = [] start_of_line = True while self.pos + 1 < len(self.data): - # pylint: disable=no-else-break c: str = self.data[self.pos] if c == "*" and self.data[self.pos + 1] == "/": self.pos += 2 diff --git a/src/karapace/rapu.py b/src/karapace/rapu.py index f31e8aab9..34d6e697c 100644 --- a/src/karapace/rapu.py +++ b/src/karapace/rapu.py @@ -20,7 +20,7 @@ import aiohttp.web import aiohttp.web_exceptions import asyncio -import cgi # pylint: disable=deprecated-module +import cgi import hashlib import logging import re @@ -176,7 +176,7 @@ def _create_aiohttp_application(self, *, config: Config) -> aiohttp.web.Applicat return aiohttp.web.Application(client_max_size=config.http_request_max_size) return aiohttp.web.Application() - async def close_by_app(self, app: aiohttp.web.Application) -> None: # pylint: disable=unused-argument + async def close_by_app(self, app: aiohttp.web.Application) -> None: await self.close() async def close(self) -> None: @@ -191,7 +191,7 @@ async def close(self) -> None: self.stats.close() @staticmethod - def cors_and_server_headers_for_request(*, request, origin="*"): # pylint: disable=unused-argument + def cors_and_server_headers_for_request(*, request, origin="*"): return { "Access-Control-Allow-Origin": origin, "Access-Control-Allow-Methods": "DELETE, GET, OPTIONS, POST, PUT", @@ -292,17 +292,11 @@ async def _handle_request( body_string = body.decode(charset) rapu_request.json = json_decode(body_string) except UnicodeDecodeError: - raise HTTPResponse( # pylint: disable=raise-missing-from - body=f"Request body is not valid {charset}", status=HTTPStatus.BAD_REQUEST - ) + raise HTTPResponse(body=f"Request body is not valid {charset}", status=HTTPStatus.BAD_REQUEST) except LookupError: - raise HTTPResponse( # pylint: disable=raise-missing-from - body=f"Unknown charset {charset}", status=HTTPStatus.BAD_REQUEST - ) + raise HTTPResponse(body=f"Unknown charset {charset}", status=HTTPStatus.BAD_REQUEST) except ValueError: - raise HTTPResponse( # pylint: disable=raise-missing-from - body="Invalid request JSON body", status=HTTPStatus.BAD_REQUEST - ) + raise HTTPResponse(body="Invalid request JSON body", status=HTTPStatus.BAD_REQUEST) # Prevent string, int etc. going further from here if not isinstance(rapu_request.json, dict): @@ -404,7 +398,7 @@ async def _handle_request( self.log.debug(error_msg, exc_info=exc) # No response can be returned and written to client, aiohttp expects some response here. resp = aiohttp.web.Response(text=error_msg, status=HTTPStatus.SERVICE_UNAVAILABLE.value) - except Exception as ex: # pylint: disable=broad-except + except Exception as ex: self.stats.unexpected_exception(ex=ex, where="rapu_wrapped_callback") self.log.exception("Unexpected error handling user request: %s %s", request.method, request.url) resp = aiohttp.web.Response(text="Internal Server Error", status=HTTPStatus.INTERNAL_SERVER_ERROR.value) diff --git a/src/karapace/sentry/sentry_client.py b/src/karapace/sentry/sentry_client.py index 3ef328132..63e8e529d 100644 --- a/src/karapace/sentry/sentry_client.py +++ b/src/karapace/sentry/sentry_client.py @@ -8,7 +8,7 @@ from collections.abc import Mapping from karapace.sentry.sentry_client_api import KarapaceSentryConfig, SentryClientAPI -# The Sentry SDK is optional, omit pylint import error +# The Sentry SDK is optional import sentry_sdk diff --git a/src/karapace/serialization.py b/src/karapace/serialization.py index 987fe6646..80aa7a96f 100644 --- a/src/karapace/serialization.py +++ b/src/karapace/serialization.py @@ -71,16 +71,16 @@ class InvalidRecord(Exception): def topic_name_strategy( topic_name: str, - record_name: str | None, # pylint: disable=unused-argument + record_name: str | None, subject_type: SubjectType, ) -> Subject: return Subject(f"{topic_name}-{subject_type}") def record_name_strategy( - topic_name: str, # pylint: disable=unused-argument, + topic_name: str, record_name: str | None, - subject_type: SubjectType, # pylint: disable=unused-argument + subject_type: SubjectType, ) -> Subject: if record_name is None: raise InvalidRecord( diff --git a/src/karapace/statsd.py b/src/karapace/statsd.py index 4342ca29d..3215374f3 100644 --- a/src/karapace/statsd.py +++ b/src/karapace/statsd.py @@ -83,7 +83,7 @@ def _send(self, metric: str, metric_type: bytes, value: Any, tags: dict | None) parts.insert(1, f",{tag}={tag_value}".encode()) self._socket.sendto(b"".join(parts), self._dest_addr) - except Exception: # pylint: disable=broad-except + except Exception: LOG.exception("Unexpected exception in statsd send") def close(self) -> None: diff --git a/src/karapace/utils.py b/src/karapace/utils.py index 22eb98182..ec9232ceb 100644 --- a/src/karapace/utils.py +++ b/src/karapace/utils.py @@ -25,11 +25,11 @@ import time if importlib.util.find_spec("ujson"): - from ujson import JSONDecodeError # noqa: F401 pylint: disable=unused-import, useless-suppression + from ujson import JSONDecodeError # noqa: F401 import ujson as json else: - from json import JSONDecodeError # noqa: F401 pylint: disable=unused-import, useless-suppression + from json import JSONDecodeError # noqa: F401 import json @@ -134,7 +134,7 @@ def json_decode( content: AnyStr | IO[AnyStr], # This argument is only used to pass onto cast() via a type var, it has no runtime # usage. - assume_type: type[T] | None = None, # pylint: disable=unused-argument + assume_type: type[T] | None = None, ) -> JsonData | T: if isinstance(content, (str, bytes)): return cast("T | None", json.loads(content)) @@ -197,7 +197,7 @@ def convert_to_int(object_: dict, key: str, content_type: str) -> None: try: object_[key] = int(object_[key]) except ValueError: - from karapace.rapu import http_error # pylint: disable=cyclic-import + from karapace.rapu import http_error http_error( message=f"{key} is not a valid int: {object_[key]}", @@ -216,7 +216,7 @@ def log( self, request: BaseRequest, response: StreamResponse, - time: float, # pylint: disable=redefined-outer-name + time: float, ) -> None: try: fmt_info = self._format_line(request, response, time) @@ -235,7 +235,7 @@ def log( extra[k1] = dct self.logger.debug(self._log_format % tuple(values), extra=extra) - except Exception: # pylint: disable=broad-except + except Exception: self.logger.exception("Error in logging") diff --git a/src/schema_registry/controller.py b/src/schema_registry/controller.py index fe658cd10..d8924d9a7 100644 --- a/src/schema_registry/controller.py +++ b/src/schema_registry/controller.py @@ -813,7 +813,7 @@ async def subject_post( except (InvalidReferences, InvalidSchema, InvalidSchemaType) as exc: LOG.warning("Invalid schema: %r", schema_request.schema_str, exc_info=True) if isinstance(exc.__cause__, (SchemaParseException, JSONDecodeError, ProtobufUnresolvedDependencyException)): - human_error = f"{exc.__cause__.args[0]}" # pylint: disable=no-member + human_error = f"{exc.__cause__.args[0]}" else: from_body_schema_str = schema_request.schema_str human_error = ( diff --git a/src/schema_registry/middlewares/__init__.py b/src/schema_registry/middlewares/__init__.py index d86fbf40e..3f137b970 100644 --- a/src/schema_registry/middlewares/__init__.py +++ b/src/schema_registry/middlewares/__init__.py @@ -27,7 +27,7 @@ async def set_content_types(request: Request, call_next: Callable[[Request], Awa if request.headers.get("Content-Type") == "application/octet-stream": new_headers = request.headers.mutablecopy() new_headers["Content-Type"] = "application/json" - request._headers = new_headers # pylint: disable=protected-access + request._headers = new_headers request.scope.update(headers=request.headers.raw) response = await call_next(request) diff --git a/src/schema_registry/reader.py b/src/schema_registry/reader.py index 6535729cb..dfe5a547c 100644 --- a/src/schema_registry/reader.py +++ b/src/schema_registry/reader.py @@ -207,7 +207,7 @@ def run(self) -> None: LOG.warning("[Admin Client] Invalid configuration. Bailing") self._stop_schema_reader.set() raise - except Exception as e: # pylint: disable=broad-except + except Exception as e: LOG.exception("[Admin Client] Unexpected exception. Retrying") self.stats.unexpected_exception(ex=e, where="admin_client_instantiation") self._stop_schema_reader.wait(timeout=KAFKA_CLIENT_CREATION_TIMEOUT_SECONDS) @@ -225,7 +225,7 @@ def run(self) -> None: LOG.warning("[Consumer] Invalid configuration. Bailing") self._stop_schema_reader.set() raise - except Exception as e: # pylint: disable=broad-except + except Exception as e: LOG.exception("[Consumer] Unexpected exception. Retrying") self.stats.unexpected_exception(ex=e, where="consumer_instantiation") self._stop_schema_reader.wait(timeout=KAFKA_CLIENT_CREATION_TIMEOUT_SECONDS) @@ -271,7 +271,7 @@ def run(self) -> None: except KafkaUnavailableError: self.consecutive_unexpected_errors += 1 LOG.warning("Kafka cluster is unavailable or broker can't be resolved.") - except Exception as e: # pylint: disable=broad-except + except Exception as e: self.stats.unexpected_exception(ex=e, where="schema_reader_loop") self.consecutive_unexpected_errors += 1 if self.consecutive_unexpected_errors == 1: @@ -301,7 +301,7 @@ async def is_healthy(self) -> bool: topic = self.config.topic_name res = self.admin_client.describe_topics(TopicCollection([topic])) await asyncio.wrap_future(res[topic]) - except Exception as e: # pylint: disable=broad-except + except Exception as e: LOG.warning("Health check failed with %r", e) return False @@ -324,7 +324,7 @@ def _get_beginning_offset(self) -> int: LOG.warning("Topic does not yet exist.") except (LeaderNotAvailableError, NotLeaderForPartitionError): LOG.warning("Retrying to find leader for schema topic partition.") - except Exception as e: # pylint: disable=broad-except + except Exception as e: self.stats.unexpected_exception(ex=e, where="_get_beginning_offset") LOG.exception("Unexpected exception when reading begin offsets.") return OFFSET_UNINITIALIZED @@ -347,7 +347,7 @@ def _is_ready(self) -> bool: except (LeaderNotAvailableError, NotLeaderForPartitionError): LOG.warning("Retrying to find leader for schema topic partition.") return False - except Exception as e: # pylint: disable=broad-except + except Exception as e: self.stats.unexpected_exception(ex=e, where="_is_ready") LOG.exception("Unexpected exception when reading end offsets.") return False @@ -570,7 +570,7 @@ def _handle_msg_config(self, key: dict, value: dict | None) -> None: LOG.info("Setting global config to: %r, value: %r", value["compatibilityLevel"], value) self.config.compatibility = value["compatibilityLevel"] - def _handle_msg_delete_subject(self, key: dict, value: dict | None) -> None: # pylint: disable=unused-argument + def _handle_msg_delete_subject(self, key: dict, value: dict | None) -> None: if value is None: LOG.warning("DELETE_SUBJECT record does not have a value, should have") raise ValueError("DELETE_SUBJECT record does not have a value, should have") diff --git a/src/schema_registry/routers/master_availability.py b/src/schema_registry/routers/master_availability.py index 02d072afd..60ac6e30d 100644 --- a/src/schema_registry/routers/master_availability.py +++ b/src/schema_registry/routers/master_availability.py @@ -46,8 +46,8 @@ async def master_availability( if ( schema_registry.schema_reader.master_coordinator is not None - and schema_registry.schema_reader.master_coordinator._sc is not None # pylint: disable=protected-access - and schema_registry.schema_reader.master_coordinator._sc.is_master_assigned_to_myself() # pylint: disable=protected-access + and schema_registry.schema_reader.master_coordinator._sc is not None + and schema_registry.schema_reader.master_coordinator._sc.is_master_assigned_to_myself() ): return MasterAvailabilityResponse(master_available=are_we_master) diff --git a/tests/conftest.py b/tests/conftest.py index 6d54c4a6a..28f565b30 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,7 +67,7 @@ def split_by_comma(arg: str) -> list[str]: return arg.split(",") -def pytest_addoption(parser, pluginmanager) -> None: # pylint: disable=unused-argument +def pytest_addoption(parser, pluginmanager) -> None: # Configuration options for the services started by the test suite parser.addoption( KAFKA_VERION_OPT, diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index f99d8c71a..eee282b42 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -96,7 +96,7 @@ async def fixture_asyncconsumer( @pytest.fixture(scope="function", name="registry_cluster") async def fixture_registry_cluster( karapace_container: KarapaceContainer, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, ) -> RegistryDescription: protocol = "http" endpoint = RegistryEndpoint( @@ -110,7 +110,7 @@ async def fixture_registry_async_client( request: SubRequest, basic_auth: BasicAuth, registry_cluster: RegistryDescription, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, ) -> AsyncGenerator[Client, None]: client = Client( server_uri=registry_cluster.endpoint.to_url(), diff --git a/tests/integration/backup/test_v3_backup.py b/tests/integration/backup/test_v3_backup.py index f7c2b8dee..0bf4b53cf 100644 --- a/tests/integration/backup/test_v3_backup.py +++ b/tests/integration/backup/test_v3_backup.py @@ -653,7 +653,7 @@ class FailToSendProducer(KafkaProducer): def send(self, *args, **kwargs): raise BufferError() - def poll(self, timeout: float) -> None: # pylint: disable=unused-argument + def poll(self, timeout: float) -> None: return class FailToSendProducerContext: diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 057546b8a..10386e832 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -266,7 +266,7 @@ async def fixture_asyncconsumer( @pytest.fixture(scope="function", name="rest_async") async def fixture_rest_async( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, kafka_servers: KafkaServers, registry_async_client: Client, ) -> AsyncIterator[KafkaRest | None]: @@ -298,7 +298,7 @@ async def fixture_rest_async( @pytest.fixture(scope="function", name="rest_async_client") async def fixture_rest_async_client( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, rest_async: KafkaRest, aiohttp_client: AiohttpClient, ) -> AsyncIterator[Client]: @@ -309,7 +309,7 @@ async def fixture_rest_async_client( client = Client(server_uri=rest_url) else: - async def get_client(**kwargs) -> TestClient: # pylint: disable=unused-argument + async def get_client(**kwargs) -> TestClient: return await aiohttp_client(rest_async.app) client = Client(client_factory=get_client) @@ -333,7 +333,7 @@ async def get_client(**kwargs) -> TestClient: # pylint: disable=unused-argument @pytest.fixture(scope="function", name="rest_async_novalidation") async def fixture_rest_async_novalidation( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, kafka_servers: KafkaServers, registry_async_client: Client, ) -> AsyncIterator[KafkaRest | None]: @@ -366,7 +366,7 @@ async def fixture_rest_async_novalidation( @pytest.fixture(scope="function", name="rest_async_novalidation_client") async def fixture_rest_async_novalidationclient( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, rest_async_novalidation: KafkaRest, aiohttp_client: AiohttpClient, ) -> AsyncIterator[Client]: @@ -377,7 +377,7 @@ async def fixture_rest_async_novalidationclient( client = Client(server_uri=rest_url) else: - async def get_client(**kwargs) -> TestClient: # pylint: disable=unused-argument + async def get_client(**kwargs) -> TestClient: return await aiohttp_client(rest_async_novalidation.app) client = Client(client_factory=get_client) @@ -401,7 +401,7 @@ async def get_client(**kwargs) -> TestClient: # pylint: disable=unused-argument @pytest.fixture(scope="function", name="rest_async_registry_auth") async def fixture_rest_async_registry_auth( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, kafka_servers: KafkaServers, registry_async_client_auth: Client, ) -> AsyncIterator[KafkaRest | None]: @@ -434,7 +434,7 @@ async def fixture_rest_async_registry_auth( @pytest.fixture(scope="function", name="rest_async_client_registry_auth") async def fixture_rest_async_client_registry_auth( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, rest_async_registry_auth: KafkaRest, aiohttp_client: AiohttpClient, ) -> AsyncIterator[Client]: @@ -445,7 +445,7 @@ async def fixture_rest_async_client_registry_auth( client = Client(server_uri=rest_url) else: - async def get_client(**kwargs) -> TestClient: # pylint: disable=unused-argument + async def get_client(**kwargs) -> TestClient: return await aiohttp_client(rest_async_registry_auth.app) client = Client(client_factory=get_client) @@ -469,7 +469,7 @@ async def get_client(**kwargs) -> TestClient: # pylint: disable=unused-argument @pytest.fixture(scope="function", name="registry_async_pair") async def fixture_registry_async_pair( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, session_logdir: Path, kafka_servers: KafkaServers, ) -> AsyncIterator[list[str]]: @@ -491,7 +491,7 @@ async def fixture_registry_async_pair( @pytest.fixture(scope="function", name="registry_cluster") async def fixture_registry_cluster( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, session_logdir: Path, kafka_servers: KafkaServers, ) -> AsyncIterator[RegistryDescription]: @@ -522,7 +522,7 @@ async def fixture_registry_cluster( async def fixture_registry_async_client( request: SubRequest, registry_cluster: RegistryDescription, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, ) -> AsyncGenerator[Client, None]: client = Client( server_uri=registry_cluster.endpoint.to_url(), @@ -576,7 +576,7 @@ def fixture_server_key(credentials_folder: str) -> str: @pytest.fixture(scope="function", name="registry_https_endpoint") async def fixture_registry_https_endpoint( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, session_logdir: Path, kafka_servers: KafkaServers, server_cert: str, @@ -605,7 +605,7 @@ async def fixture_registry_https_endpoint( @pytest.fixture(scope="function", name="registry_async_client_tls") async def fixture_registry_async_client_tls( - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, registry_https_endpoint: str, server_ca: str, ) -> AsyncIterator[Client]: @@ -635,7 +635,7 @@ async def fixture_registry_async_client_tls( @pytest.fixture(scope="function", name="registry_http_auth_endpoint") async def fixture_registry_http_auth_endpoint( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, session_logdir: Path, kafka_servers: KafkaServers, ) -> AsyncIterator[str]: @@ -662,7 +662,7 @@ async def fixture_registry_http_auth_endpoint( @pytest.fixture(scope="function", name="registry_async_client_auth") async def fixture_registry_async_client_auth( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, registry_http_auth_endpoint: str, ) -> AsyncIterator[Client]: client = Client( @@ -695,7 +695,7 @@ async def fixture_registry_async_retry_client_auth(registry_async_client_auth: C @pytest.fixture(scope="function", name="registry_async_auth_pair") async def fixture_registry_async_auth_pair( request: SubRequest, - loop: asyncio.AbstractEventLoop, # pylint: disable=unused-argument + loop: asyncio.AbstractEventLoop, session_logdir: Path, kafka_servers: KafkaServers, ) -> AsyncIterator[list[str]]: diff --git a/tests/integration/test_schema_compatibility.py b/tests/integration/test_schema_compatibility.py index cf8c8fa01..3320c3a4c 100644 --- a/tests/integration/test_schema_compatibility.py +++ b/tests/integration/test_schema_compatibility.py @@ -102,7 +102,7 @@ async def _register_baseline_schemas_with_incompatibilities_and_a_deleted_schema async def _register_no_baseline_schemas( registry_async_client: Client, - subject: Subject, # pylint: disable=unused-argument + subject: Subject, ) -> None: pass diff --git a/tests/integration/test_schema_coordinator.py b/tests/integration/test_schema_coordinator.py index 2d8e2bae7..08839d667 100644 --- a/tests/integration/test_schema_coordinator.py +++ b/tests/integration/test_schema_coordinator.py @@ -55,7 +55,7 @@ def fixture_mocked_aiokafka_client() -> Iterator[AIOKafkaClient]: @pytest.fixture(scope="function", name="coordinator") async def fixture_admin( loop: asyncio.AbstractEventLoop, - mocked_client: AIOKafkaClient, # pylint: disable=unused-argument + mocked_client: AIOKafkaClient, ) -> AsyncGenerator: coordinator = SchemaCoordinator( mocked_client, @@ -87,7 +87,7 @@ async def _get_client(kafka_servers: KafkaServers) -> AIOKafkaClient: @pytest.fixture(scope="function", name="client") async def get_client( loop: asyncio.AbstractEventLoop, - kafka_servers: KafkaServers, # pylint: disable=unused-argument + kafka_servers: KafkaServers, ) -> AsyncGenerator: client = await _get_client(kafka_servers) yield client @@ -218,14 +218,14 @@ async def test_coordinator_workflow( async def test_failed_group_join(mocked_client: AIOKafkaClient, coordinator: SchemaCoordinator) -> None: coordinator.start() - assert coordinator._coordination_task is not None # pylint: disable=protected-access - assert coordinator._client is not None # pylint: disable=protected-access + assert coordinator._coordination_task is not None + assert coordinator._client is not None # disable for test - coordinator._coordination_task.cancel() # pylint: disable=protected-access + coordinator._coordination_task.cancel() with contextlib.suppress(asyncio.CancelledError): - await coordinator._coordination_task # pylint: disable=protected-access - coordinator._coordination_task = create_task(asyncio.sleep(0.1)) # pylint: disable=protected-access + await coordinator._coordination_task + coordinator._coordination_task = create_task(asyncio.sleep(0.1)) coordinator.coordinator_id = 15 async def _on_join_leader_test(_: Response) -> bytes | None: @@ -239,13 +239,13 @@ async def do_rebalance() -> Assignment | None: coordinator, coordinator.group_id, coordinator.coordinator_id, - coordinator._session_timeout_ms, # pylint: disable=protected-access - coordinator._retry_backoff_ms, # pylint: disable=protected-access + coordinator._session_timeout_ms, + coordinator._retry_backoff_ms, ) - rebalance._on_join_leader = _on_join_leader_mock # pylint: disable=protected-access + rebalance._on_join_leader = _on_join_leader_mock return await rebalance.perform_group_join() - coordinator._client.api_version = (0, 10, 1) # pylint: disable=protected-access + coordinator._client.api_version = (0, 10, 1) error_type = Errors.NoError async def send(*_, **__) -> JoinGroupRequest: @@ -296,7 +296,7 @@ async def send(*_, **__) -> JoinGroupRequest: assert coordinator.need_rejoin() assert coordinator.coordinator_id is None coordinator.coordinator_id = 15 - coordinator._coordinator_dead_fut = create_future() # pylint: disable=protected-access + coordinator._coordinator_dead_fut = create_future() async def _on_join_leader(_) -> bytes | None: return None @@ -319,14 +319,14 @@ async def _on_join_leader(_) -> bytes | None: async def test_failed_sync_group(mocked_client: AIOKafkaClient, coordinator: SchemaCoordinator) -> None: coordinator.start() - assert coordinator._coordination_task is not None # pylint: disable=protected-access - assert coordinator._client is not None # pylint: disable=protected-access + assert coordinator._coordination_task is not None + assert coordinator._client is not None # disable for test - coordinator._coordination_task.cancel() # pylint: disable=protected-access + coordinator._coordination_task.cancel() with contextlib.suppress(asyncio.CancelledError): - await coordinator._coordination_task # pylint: disable=protected-access - coordinator._coordination_task = create_task(asyncio.sleep(0.1)) # pylint: disable=protected-access + await coordinator._coordination_task + coordinator._coordination_task = create_task(asyncio.sleep(0.1)) coordinator.coordinator_id = 15 async def do_sync_group() -> bytes | None: @@ -334,12 +334,12 @@ async def do_sync_group() -> bytes | None: coordinator, coordinator.group_id, coordinator.coordinator_id, - coordinator._session_timeout_ms, # pylint: disable=protected-access - coordinator._retry_backoff_ms, # pylint: disable=protected-access + coordinator._session_timeout_ms, + coordinator._retry_backoff_ms, ) - await rebalance._on_join_follower() # pylint: disable=protected-access + await rebalance._on_join_follower() - coordinator._client.api_version = (0, 10, 1) # pylint: disable=protected-access + coordinator._client.api_version = (0, 10, 1) error_type = None async def send(*_, **__) -> SyncGroupResponse: @@ -366,7 +366,7 @@ async def send(*_, **__) -> SyncGroupResponse: assert coordinator.need_rejoin() coordinator.coordinator_id = 15 - coordinator._coordinator_dead_fut = create_future() # pylint: disable=protected-access + coordinator._coordinator_dead_fut = create_future() error_type = Errors.UnknownError() with pytest.raises(Errors.KafkaError): # Masked as some KafkaError @@ -391,9 +391,9 @@ async def test_generation_change_during_rejoin_sync() -> None: coordinator = mock.MagicMock(spec=SchemaCoordinator) member_assignment = mock.Mock(spec=Assignment) - coordinator._client = client # pylint: disable=protected-access - coordinator._rebalance_timeout_ms = 1000 # pylint: disable=protected-access - coordinator._send_req = mock.MagicMock() # pylint: disable=protected-access + coordinator._client = client + coordinator._rebalance_timeout_ms = 1000 + coordinator._send_req = mock.MagicMock() rebalance = SchemaCoordinatorGroupRebalance( coordinator, @@ -415,7 +415,7 @@ async def send_req(_) -> Response: request = mock.MagicMock() coordinator.generation = 1 coordinator.member_id = "member_id" - sync_req = asyncio.ensure_future(rebalance._send_sync_group_request(request)) # pylint: disable=protected-access + sync_req = asyncio.ensure_future(rebalance._send_sync_group_request(request)) await asyncio.sleep(0.05) coordinator.generation = -1 @@ -445,7 +445,7 @@ async def test_coordinator_metadata_update(client: AIOKafkaClient) -> None: ) coordinator.start() - _metadata_update = client._metadata_update # pylint: disable=protected-access + _metadata_update = client._metadata_update with mock.patch.object(client, "_metadata_update") as mocked: async def _new(*args, **kw) -> bool: @@ -526,13 +526,13 @@ async def test_coordinator_ensure_coordinator_known(client: AIOKafkaClient) -> N heartbeat_interval_ms=20000, ) coordinator.start() - assert coordinator._coordination_task is not None # pylint: disable=protected-access + assert coordinator._coordination_task is not None # disable for test - coordinator._coordination_task.cancel() # pylint: disable=protected-access + coordinator._coordination_task.cancel() with contextlib.suppress(asyncio.CancelledError): - await coordinator._coordination_task # pylint: disable=protected-access - coordinator._coordination_task = create_task(asyncio.sleep(0.1)) # pylint: disable=protected-access + await coordinator._coordination_task + coordinator._coordination_task = create_task(asyncio.sleep(0.1)) def force_metadata_update() -> asyncio.Future: fut = create_future() @@ -543,7 +543,7 @@ def force_metadata_update() -> asyncio.Future: client.force_metadata_update = mock.Mock() client.force_metadata_update.side_effect = force_metadata_update - async def ready(node_id: int, group: ConnectionGroup) -> bool: # pylint: disable=unused-argument + async def ready(node_id: int, group: ConnectionGroup) -> bool: if node_id == 0: return True return False @@ -608,12 +608,12 @@ async def test_coordinator__do_heartbeat(client: AIOKafkaClient) -> None: heartbeat_interval_ms=20000, ) coordinator.start() - assert coordinator._coordination_task is not None # pylint: disable=protected-access + assert coordinator._coordination_task is not None # disable for test - coordinator._coordination_task.cancel() # pylint: disable=protected-access + coordinator._coordination_task.cancel() with contextlib.suppress(asyncio.CancelledError): - await coordinator._coordination_task # pylint: disable=protected-access - coordinator._coordination_task = create_task(asyncio.sleep(0.1)) # pylint: disable=protected-access + await coordinator._coordination_task + coordinator._coordination_task = create_task(asyncio.sleep(0.1)) _orig_send_req = coordinator.send_req coordinator.send_req = mocked = mock.Mock() @@ -635,20 +635,20 @@ async def mock_send_req(request): coordinator.coordinator_id = 15 heartbeat_error = Errors.GroupCoordinatorNotAvailableError() - success = await coordinator._do_heartbeat() # pylint: disable=protected-access + success = await coordinator._do_heartbeat() assert not success assert coordinator.coordinator_id is None coordinator.rejoin_needed_fut = create_future() heartbeat_error = Errors.RebalanceInProgressError() - success = await coordinator._do_heartbeat() # pylint: disable=protected-access + success = await coordinator._do_heartbeat() assert success assert coordinator.rejoin_needed_fut.done() coordinator.member_id = "some_member" coordinator.rejoin_needed_fut = create_future() heartbeat_error = Errors.IllegalGenerationError() - success = await coordinator._do_heartbeat() # pylint: disable=protected-access + success = await coordinator._do_heartbeat() assert not success assert coordinator.rejoin_needed_fut.done() assert coordinator.member_id == UNKNOWN_MEMBER_ID @@ -656,28 +656,28 @@ async def mock_send_req(request): coordinator.member_id = "some_member" coordinator.rejoin_needed_fut = create_future() heartbeat_error = Errors.UnknownMemberIdError() - success = await coordinator._do_heartbeat() # pylint: disable=protected-access + success = await coordinator._do_heartbeat() assert not success assert coordinator.rejoin_needed_fut.done() assert coordinator.member_id == UNKNOWN_MEMBER_ID heartbeat_error = Errors.GroupAuthorizationFailedError() with pytest.raises(Errors.GroupAuthorizationFailedError) as exception_info: - await coordinator._do_heartbeat() # pylint: disable=protected-access + await coordinator._do_heartbeat() assert exception_info.value.args[0] == coordinator.group_id heartbeat_error = Errors.UnknownError() with pytest.raises(Errors.KafkaError): - await coordinator._do_heartbeat() # pylint: disable=protected-access + await coordinator._do_heartbeat() heartbeat_error = None send_req_error = Errors.RequestTimedOutError() - success = await coordinator._do_heartbeat() # pylint: disable=protected-access + success = await coordinator._do_heartbeat() assert not success heartbeat_error = Errors.NoError() send_req_error = None - success = await coordinator._do_heartbeat() # pylint: disable=protected-access + success = await coordinator._do_heartbeat() assert success finally: await coordinator.close() @@ -699,15 +699,15 @@ async def test_coordinator__heartbeat_routine(client: AIOKafkaClient) -> None: retry_backoff_ms=50, ) coordinator.start() - assert coordinator._coordination_task is not None # pylint: disable=protected-access + assert coordinator._coordination_task is not None # disable for test - coordinator._coordination_task.cancel() # pylint: disable=protected-access + coordinator._coordination_task.cancel() with contextlib.suppress(asyncio.CancelledError): - await coordinator._coordination_task # pylint: disable=protected-access - coordinator._coordination_task = create_task(asyncio.sleep(0.1)) # pylint: disable=protected-access + await coordinator._coordination_task + coordinator._coordination_task = create_task(asyncio.sleep(0.1)) mocked = mock.Mock() - coordinator._do_heartbeat = mocked # pylint: disable=protected-access + coordinator._do_heartbeat = mocked coordinator.coordinator_id = 15 coordinator.member_id = 17 coordinator.generation = 0 @@ -726,7 +726,7 @@ async def ensure_coordinator_known() -> None: coordinator.ensure_coordinator_known = mock.Mock() coordinator.ensure_coordinator_known.side_effect = ensure_coordinator_known - routine = create_task(coordinator._heartbeat_routine()) # pylint: disable=protected-access + routine = create_task(coordinator._heartbeat_routine()) # CASE: simple heartbeat success = True @@ -771,20 +771,18 @@ async def test_coordinator__coordination_routine(client: AIOKafkaClient) -> None ) def start_coordination(): - if coordinator._coordination_task: # pylint: disable=protected-access - coordinator._coordination_task.cancel() # pylint: disable=protected-access - coordinator._coordination_task = task = create_task( # pylint: disable=protected-access - coordinator._coordination_routine() # pylint: disable=protected-access - ) + if coordinator._coordination_task: + coordinator._coordination_task.cancel() + coordinator._coordination_task = task = create_task(coordinator._coordination_routine()) return task async def stop_coordination(): - if coordinator._coordination_task is not None: # pylint: disable=protected-access + if coordinator._coordination_task is not None: # disable for test - coordinator._coordination_task.cancel() # pylint: disable=protected-access + coordinator._coordination_task.cancel() with contextlib.suppress(asyncio.CancelledError): - await coordinator._coordination_task # pylint: disable=protected-access - coordinator._coordination_task = create_task(asyncio.sleep(0.1)) # pylint: disable=protected-access + await coordinator._coordination_task + coordinator._coordination_task = create_task(asyncio.sleep(0.1)) await stop_coordination() @@ -794,7 +792,7 @@ async def ensure_coordinator_known(): coordinator.ensure_coordinator_known = coord_mock = mock.Mock() coord_mock.side_effect = ensure_coordinator_known - coordinator._do_rejoin_group = rejoin_mock = mock.Mock() # pylint: disable=protected-access + coordinator._do_rejoin_group = rejoin_mock = mock.Mock() rejoin_ok = True async def do_rejoin(): @@ -806,15 +804,15 @@ async def do_rejoin(): rejoin_mock.side_effect = do_rejoin - coordinator._start_heartbeat_task = mock.Mock() # pylint: disable=protected-access + coordinator._start_heartbeat_task = mock.Mock() client.force_metadata_update = metadata_mock = mock.Mock() done_fut = create_future() done_fut.set_result(None) metadata_mock.side_effect = lambda: done_fut coordinator.rejoin_needed_fut = create_future() - coordinator._closing = create_future() # pylint: disable=protected-access - coordinator._coordinator_dead_fut = create_future() # pylint: disable=protected-access + coordinator._closing = create_future() + coordinator._coordinator_dead_fut = create_future() # CASE: coordination should coordinate and task get done # present diff --git a/tests/integration/test_schema_reader.py b/tests/integration/test_schema_reader.py index 578390d7e..7b14d3ebb 100644 --- a/tests/integration/test_schema_reader.py +++ b/tests/integration/test_schema_reader.py @@ -109,7 +109,7 @@ async def test_regression_soft_delete_schemas_should_be_registered( producer.flush() msg = future.result() - schema_reader._offset_watcher.wait_for_offset(msg.offset(), timeout=5) # pylint: disable=protected-access + schema_reader._offset_watcher.wait_for_offset(msg.offset(), timeout=5) schemas = database.find_subject_schemas(subject=subject, include_deleted=True) assert len(schemas) == 1, "Deleted schemas must have been registered" @@ -137,7 +137,7 @@ async def test_regression_soft_delete_schemas_should_be_registered( producer.flush() msg = future.result() - seen = schema_reader._offset_watcher.wait_for_offset(msg.offset(), timeout=5) # pylint: disable=protected-access + seen = schema_reader._offset_watcher.wait_for_offset(msg.offset(), timeout=5) assert seen is True assert database.global_schema_id == test_global_schema_id @@ -194,7 +194,7 @@ async def test_regression_config_for_inexisting_object_should_not_throw( producer.flush() msg = future.result() - seen = schema_reader._offset_watcher.wait_for_offset(msg.offset(), timeout=5) # pylint: disable=protected-access + seen = schema_reader._offset_watcher.wait_for_offset(msg.offset(), timeout=5) assert seen is True assert database.find_subject(subject=subject) is not None, "The above message should be handled gracefully" finally: diff --git a/tests/integration/utils/kafka_server.py b/tests/integration/utils/kafka_server.py index 2a6a67082..f018bc097 100644 --- a/tests/integration/utils/kafka_server.py +++ b/tests/integration/utils/kafka_server.py @@ -184,5 +184,5 @@ def configure_and_start_kafka( ), ) env: dict[bytes, bytes] = {} - proc = Popen(kafka_cmd, env=env) # pylint: disable=consider-using-with + proc = Popen(kafka_cmd, env=env) return proc diff --git a/tests/integration/utils/zookeeper.py b/tests/integration/utils/zookeeper.py index e08d0fed5..39c0c2302 100644 --- a/tests/integration/utils/zookeeper.py +++ b/tests/integration/utils/zookeeper.py @@ -59,5 +59,5 @@ def configure_and_start_zk(config: ZKConfig, kafka_description: KafkaDescription kafka_description, ) ) - proc = Popen(java_args, env=env) # pylint: disable=consider-using-with + proc = Popen(java_args, env=env) return proc diff --git a/tests/unit/anonymize_schemas/test_anonymize_avro.py b/tests/unit/anonymize_schemas/test_anonymize_avro.py index 1e69bbddc..9c9311a89 100644 --- a/tests/unit/anonymize_schemas/test_anonymize_avro.py +++ b/tests/unit/anonymize_schemas/test_anonymize_avro.py @@ -13,8 +13,6 @@ PRIMITIVE_TYPE_SCHEMA = json.loads('"int"') EXPECTED_PRIMITIVE_TYPE_SCHEMA = "int" -# Pylint issue: https://github.com/PyCQA/pylint/issues/3368 -# pylint: disable=line-too-long SCHEMA_WITH_NAME = json.loads('"io.aiven.myrecord"') EXPECTED_SCHEMA_WITH_NAME = "aa258230180d9c643f761089d7e33b8b52288ed3.ae02f26b082c5f3bc7027f72335dd1186a2cd382.afe8733e983101f1f4ff50d24152890d0da71418" diff --git a/tests/unit/backup/backends/test_v2.py b/tests/unit/backup/backends/test_v2.py index b525f30e7..72b175da2 100644 --- a/tests/unit/backup/backends/test_v2.py +++ b/tests/unit/backup/backends/test_v2.py @@ -91,7 +91,7 @@ def test_schema_backup_v2_roundtrip(tmp_path: Path) -> None: with backup_writer.safe_writer(file_path, False) as buffer: for record in records: backup_writer.store_record(buffer, record) - data_file = backup_writer.finalize_partition( # pylint: disable=assignment-from-no-return + data_file = backup_writer.finalize_partition( index=partition_index, filename=file_path.name, ) @@ -232,7 +232,7 @@ def test_anonymize_avro_roundtrip(tmp_path: Path) -> None: with backup_writer.safe_writer(file_path, False) as buffer: for record in records: backup_writer.store_record(buffer, record) - data_file = backup_writer.finalize_partition( # pylint: disable=assignment-from-no-return + data_file = backup_writer.finalize_partition( index=partition_index, filename=file_path.name, ) diff --git a/tests/unit/backup/backends/v3/test_backend.py b/tests/unit/backup/backends/v3/test_backend.py index 0ffad9fb5..83007f097 100644 --- a/tests/unit/backup/backends/v3/test_backend.py +++ b/tests/unit/backup/backends/v3/test_backend.py @@ -191,7 +191,7 @@ def test_reader_raises_invalid_checksum(tmp_path: Path) -> None: backup_writer.store_record(buffer, make_record(topic_name, partition_index, 0)) backup_writer.store_record(buffer, make_record(topic_name, partition_index, 1)) with mock.patch.object( - backup_writer._partition_stats[partition_index], # pylint: disable=protected-access + backup_writer._partition_stats[partition_index], "get_checkpoint", return_value=b"not what you expected!", autospec=True, diff --git a/tests/unit/instrumentation/test_prometheus.py b/tests/unit/instrumentation/test_prometheus.py index c4b3da8d9..57fb9292a 100644 --- a/tests/unit/instrumentation/test_prometheus.py +++ b/tests/unit/instrumentation/test_prometheus.py @@ -92,7 +92,7 @@ async def test_http_request_metrics_middleware( await prometheus.http_request_metrics_middleware(request=request, handler=handler) - assert handler.assert_awaited_once # extra assert is to ignore pylint [pointless-statement] + assert handler.assert_awaited_once request.__setitem__.assert_called_once_with(prometheus.START_TIME_REQUEST_KEY, 10) request.app[prometheus.karapace_http_requests_in_progress].labels.assert_has_calls( [ diff --git a/tests/unit/kafka_rest_apis/test_rest_proxy_cluster_metadata_cache.py b/tests/unit/kafka_rest_apis/test_rest_proxy_cluster_metadata_cache.py index d1227fbc2..eb4d51423 100644 --- a/tests/unit/kafka_rest_apis/test_rest_proxy_cluster_metadata_cache.py +++ b/tests/unit/kafka_rest_apis/test_rest_proxy_cluster_metadata_cache.py @@ -1,4 +1,3 @@ -# pylint: disable=protected-access """ Copyright (c) 2024 Aiven Ltd See LICENSE for details diff --git a/tests/unit/schema_registry/test_controller.py b/tests/unit/schema_registry/test_controller.py index e07f45fff..211958f28 100644 --- a/tests/unit/schema_registry/test_controller.py +++ b/tests/unit/schema_registry/test_controller.py @@ -33,12 +33,12 @@ async def test_validate_schema_request_body(schema_registry_container: SchemaRegistryContainer) -> None: - schema_registry_container.schema_registry_controller()._validate_schema_type( # pylint: disable=W0212 + schema_registry_container.schema_registry_controller()._validate_schema_type( {"schema": "{}", "schemaType": "JSON", "references": [], "metadata": {}, "ruleSet": {}} ) with pytest.raises(HTTPException) as exc_info: - schema_registry_container.schema_registry_controller()._validate_schema_type( # pylint: disable=W0212 + schema_registry_container.schema_registry_controller()._validate_schema_type( {"schema": "{}", "schemaType": "DOES_NOT_EXIST", "references": [], "unexpected_field_name": {}, "ruleSet": {}}, ) assert exc_info.type is HTTPException @@ -68,7 +68,7 @@ async def test_forward_when_not_ready(schema_registry_container: SchemaRegistryC mock_forward_func_future.set_exception(HTTPResponse({"mock": "response"})) mock_forward_func = Mock() mock_forward_func.return_value = mock_forward_func_future - controller._forward_request_remote = mock_forward_func # pylint: disable=protected-access + controller._forward_request_remote = mock_forward_func assert await controller.schemas_get( schema_id=1, diff --git a/tests/unit/schema_registry/test_reader.py b/tests/unit/schema_registry/test_reader.py index e1e9e0db5..842a74513 100644 --- a/tests/unit/schema_registry/test_reader.py +++ b/tests/unit/schema_registry/test_reader.py @@ -81,9 +81,7 @@ def produce() -> None: assert consumer.result() is None, "Thread should finish without errors" assert producer.result() is None, "Thread should finish without errors" - assert ( - watcher._greatest_offset == 99 # pylint: disable=protected-access - ), "Expected greatest offset is not one less than total count" + assert watcher._greatest_offset == 99, "Expected greatest offset is not one less than total count" assert produced_cnt == 100, "Did not produce expected amount of records" assert consumed_cnt == 100, "Did not consume expected amount of records" @@ -319,9 +317,7 @@ def test_handle_msg_delete_subject_logs(caplog: LogCaptureFixture, karapace_cont ) with caplog.at_level(logging.WARNING, logger="schema_registry.reader"): - schema_reader._handle_msg_schema_hard_delete( # pylint: disable=protected-access - key={"subject": "test-subject", "version": 2} - ) + schema_reader._handle_msg_schema_hard_delete(key={"subject": "test-subject", "version": 2}) for log in caplog.records: assert log.name == "schema_registry.reader" assert log.levelname == "WARNING" diff --git a/tests/unit/test_avro_compatibility.py b/tests/unit/test_avro_compatibility.py index 288fbeda5..771d8fc1c 100644 --- a/tests/unit/test_avro_compatibility.py +++ b/tests/unit/test_avro_compatibility.py @@ -642,12 +642,11 @@ def test_union_to_simple_comparison(field): INT_LIST_RECORD._fields = (INT_LIST_RECORD.fields[0], int_reader_field) LONG_LIST_RECORD._fields = (LONG_LIST_RECORD.fields[0], long_reader_field) -# pylint: disable=protected-access + INT_LIST_RECORD._field_map = INT_LIST_RECORD.fields_dict LONG_LIST_RECORD._field_map = LONG_LIST_RECORD.fields_dict INT_LIST_RECORD._props["fields"] = INT_LIST_RECORD._fields LONG_LIST_RECORD._props["fields"] = LONG_LIST_RECORD._fields -# pylint: enable=protected-access RECORD1_WITH_INT = parse_avro_schema_definition( json.dumps({"type": "record", "name": "Record1", "fields": [{"name": "field1", "type": "int"}]}) ) diff --git a/tests/unit/test_forwarding_client.py b/tests/unit/test_forwarding_client.py index 34df7869f..bbc449b27 100644 --- a/tests/unit/test_forwarding_client.py +++ b/tests/unit/test_forwarding_client.py @@ -41,7 +41,7 @@ def fixture_forward_client() -> ForwardClient: async def test_forward_client_close(forward_client: ForwardClient) -> None: await forward_client.close() - forward_client._forward_client.close.assert_awaited_once() # pylint: disable=protected-access + forward_client._forward_client.close.assert_awaited_once() @pytest.mark.parametrize( @@ -80,7 +80,7 @@ async def mock_aexit(_, __, ___, ____) -> None: mock_get_func.__aenter__ = mock_aenter mock_get_func.__aexit__ = mock_aexit - forward_client._forward_client.get.return_value = mock_get_func # pylint: disable=protected-access + forward_client._forward_client.get.return_value = mock_get_func response = await forward_client.forward_request_remote( request=mock_request, @@ -113,7 +113,7 @@ async def mock_aexit(_, __, ___, ____) -> None: mock_get_func.__aenter__ = mock_aenter mock_get_func.__aexit__ = mock_aexit - forward_client._forward_client.get.return_value = mock_get_func # pylint: disable=protected-access + forward_client._forward_client.get.return_value = mock_get_func response = await forward_client.forward_request_remote( request=mock_request, @@ -146,7 +146,7 @@ async def mock_aexit(_, __, ___, ____) -> None: mock_get_func.__aenter__ = mock_aenter mock_get_func.__aexit__ = mock_aexit - forward_client._forward_client.get.return_value = mock_get_func # pylint: disable=protected-access + forward_client._forward_client.get.return_value = mock_get_func response = await forward_client.forward_request_remote( request=mock_request, diff --git a/tests/unit/test_rapu.py b/tests/unit/test_rapu.py index b965dc09b..eb6185866 100644 --- a/tests/unit/test_rapu.py +++ b/tests/unit/test_rapu.py @@ -177,7 +177,7 @@ async def test_raise_connection_error_handling( app = KarapaceBase(config=karapace_container.config()) - response = await app._handle_request( # pylint: disable=protected-access + response = await app._handle_request( request=request_mock, path_for_stats="/", callback=callback_mock, diff --git a/tests/unit/test_rest_auth.py b/tests/unit/test_rest_auth.py index aa7bd41b6..ffe3ce4c2 100644 --- a/tests/unit/test_rest_auth.py +++ b/tests/unit/test_rest_auth.py @@ -1,4 +1,3 @@ -# pylint: disable=protected-access """ Copyright (c) 2023 Aiven Ltd See LICENSE for details diff --git a/website/source/conf.py b/website/source/conf.py index b1778d4ea..caa77b36b 100644 --- a/website/source/conf.py +++ b/website/source/conf.py @@ -25,7 +25,7 @@ # -- Project information ----------------------------------------------------- project = "Karapace" -copyright = "2022, Aiven" # pylint: disable=redefined-builtin +copyright = "2022, Aiven" author = "Aiven"