Skip to content

Commit

Permalink
chore: remove Python 3.8 related code
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaakola-aiven committed Oct 8, 2024
1 parent 4b32fda commit 8e9b478
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 48 deletions.
6 changes: 1 addition & 5 deletions src/karapace/avro_dataclasses/introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from dataclasses import Field, fields, is_dataclass, MISSING
from enum import Enum
from functools import lru_cache
from typing import Final, Sequence, TYPE_CHECKING, TypeVar, Union

# Note: It's important get_args and get_origin are imported from typing_extensions
# until support for Python 3.8 is dropped.
from typing_extensions import get_args, get_origin
from typing import Final, Sequence, TYPE_CHECKING, TypeVar, Union, get_args, get_origin

import datetime
import uuid
Expand Down
3 changes: 1 addition & 2 deletions src/karapace/protobuf/proto_normalizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from karapace.protobuf.service_element import ServiceElement
from karapace.protobuf.type_element import TypeElement
from karapace.protobuf.type_tree import TypeTree
from karapace.utils import remove_prefix
from typing import Sequence

import abc
Expand Down Expand Up @@ -90,7 +89,7 @@ class NormalizedOneOfElement(OneOfElement):

def normalize_type_field_element(type_field: FieldElement, package: str, type_tree: TypeTree) -> NormalizedFieldElement:
sorted_options = None if type_field.options is None else list(sorted(type_field.options, key=sort_by_name))
field_type_normalized = remove_prefix(remove_prefix(type_field.element_type, "."), f"{package}.")
field_type_normalized = type_field.element_type.removeprefix(".").removeprefix(f"{package}.")
reference_in_type_tree = type_tree.type_in_tree(field_type_normalized)
google_included_type = (
field_type_normalized in KnownDependency.index_simple or field_type_normalized in KnownDependency.index
Expand Down
3 changes: 1 addition & 2 deletions src/karapace/protobuf/type_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from collections.abc import Iterable, Sequence
from karapace.dataclasses import default_dataclass
from karapace.utils import remove_prefix

import itertools

Expand Down Expand Up @@ -84,7 +83,7 @@ def _type_in_tree(tree: TypeTree, remaining_tokens: list[str]) -> TypeTree | Non
return tree

def type_in_tree(self, queried_type: str) -> TypeTree | None:
return TypeTree._type_in_tree(self, remove_prefix(queried_type, ".").split("."))
return TypeTree._type_in_tree(self, queried_type.removeprefix(".").split("."))

def expand_missing_absolute_path(self) -> Sequence[str]:
oldest_import = self.oldest_matching_import()
Expand Down
13 changes: 0 additions & 13 deletions src/karapace/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,6 @@ def log(
self.logger.exception("Error in logging")


def remove_prefix(string: str, prefix: str) -> str:
"""
Not available in python 3.8.
"""
i = 0
while i < len(string) and i < len(prefix):
if string[i] != prefix[i]:
return string
i += 1

return string[i:]


def shutdown():
"""
Send a SIGTERM into the current running application process, which should initiate shutdown logic.
Expand Down
27 changes: 1 addition & 26 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,12 @@
See LICENSE for details
"""
from _pytest.logging import LogCaptureFixture
from karapace.utils import remove_prefix, shutdown
from karapace.utils import shutdown
from unittest.mock import patch

import logging


def test_remove_prefix_basic() -> None:
result = remove_prefix("hello world", "hello ")
assert result == "world"


def test_remove_prefix_empty_prefix() -> None:
result = remove_prefix("hello world", "")
assert result == "hello world"


def test_remove_prefix_prefix_not_in_string() -> None:
result = remove_prefix("hello world", "hey ")
assert result == "hello world"


def test_remove_prefix_multiple_occurrences_of_prefix() -> None:
result = remove_prefix("hello hello world", "hello ")
assert result == "hello world"


def test_remove_prefix_empty_string() -> None:
result = remove_prefix("", "hello ")
assert result == ""


def test_shutdown(caplog: LogCaptureFixture) -> None:
with caplog.at_level(logging.WARNING, logger="karapace.utils"):
with patch("karapace.utils.signal") as mock_signal:
Expand Down

0 comments on commit 8e9b478

Please sign in to comment.