Skip to content

Commit 29e51b1

Browse files
committed
fix: Adds support for python 3.9
1 parent 552cba4 commit 29e51b1

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/kubedantic/extractor.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import json
22
import logging
33
from pathlib import Path
4-
from typing import Any, Generator, Optional, Union
4+
from typing import Any, Dict, Generator, List, Optional, Union
55

66
from kubernetes import client, config
77
from pydantic import BaseModel, Field
88

99
logger = logging.getLogger(__name__)
1010

1111

12-
API_PATH_BY_TITLE: dict[str, Path] = {
12+
API_PATH_BY_TITLE: Dict[str, Path] = {
1313
"Kubernetes": Path("k8s"), # Kubernetes API
1414
"Kubernetes CRD Swagger": Path("crd"), # CustomResourceDefinition API
1515
}
@@ -29,7 +29,7 @@ def path(self) -> Path:
2929
return API_PATH_BY_TITLE.get(self.title, Path(""))
3030

3131
@classmethod
32-
def from_spec(cls, spec: dict[str, Any]) -> "SchemaMetadata":
32+
def from_spec(cls, spec: Dict[str, Any]) -> "SchemaMetadata":
3333
return cls(
3434
openapi=spec["openapi"],
3535
title=spec["info"]["title"],
@@ -38,10 +38,10 @@ def from_spec(cls, spec: dict[str, Any]) -> "SchemaMetadata":
3838

3939

4040
class Schema(BaseModel):
41-
openapi_schema: dict[str, Any] = Field(default_factory=dict)
41+
openapi_schema: Dict[str, Any] = Field(default_factory=dict)
4242
metadata: SchemaMetadata
4343

44-
def to_openapi(self) -> dict[str, Any]:
44+
def to_openapi(self) -> Dict[str, Any]:
4545
return {
4646
"openapi": self.metadata.openapi,
4747
"info": {"title": self.metadata.title, "version": self.metadata.version},
@@ -66,7 +66,7 @@ def _should_skip_path(self, path: str) -> bool:
6666
stem = Path(path.split("?")[0]).stem
6767
return not stem.startswith("v") or stem == "version"
6868

69-
def _add_to_schema_by_path(self, spec: dict[str, Any]):
69+
def _add_to_schema_by_path(self, spec: Dict[str, Any]):
7070
spec_metadata = SchemaMetadata.from_spec(spec)
7171

7272
if not spec_metadata.is_supported:
@@ -129,7 +129,7 @@ def _load_specs(self) -> Generator[Path, None, None]:
129129
for path, schemas in self.schema_by_path.items()
130130
)
131131

132-
def extract(self) -> list[Path]:
132+
def extract(self) -> List[Path]:
133133
"""
134134
Extracts the Kubernetes OpenAPI specs and writes them to the output path.
135135

src/kubedantic/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import sys
44
from pathlib import Path
5+
from typing import Tuple
56

67
from datamodel_code_generator.parser.base import Result
78

@@ -38,7 +39,7 @@ def _get_options(args):
3839
return parser.parse_args(args)
3940

4041

41-
def _write_result(path: tuple[str, ...], result: Result, output_path: Path):
42+
def _write_result(path: Tuple[str, ...], result: Result, output_path: Path):
4243
output_file = output_path.joinpath(*path[1:]).with_suffix(".py")
4344
logging.info("Generating %s", output_file)
4445
output_file.parent.mkdir(parents=True, exist_ok=True)

src/kubedantic/parser.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import sys
33
from pathlib import Path
4-
from typing import Any, Optional, Union
4+
from typing import Any, List, Optional, Tuple, Union
55
from urllib.parse import ParseResult
66

77
from datamodel_code_generator.format import PythonVersion
@@ -20,7 +20,7 @@ def _get_python_version() -> PythonVersion:
2020

2121

2222
class K8sSchemaObject(JsonSchemaObject):
23-
def _get_group_version_kind(self) -> tuple[str, str, str]:
23+
def _get_group_version_kind(self) -> Tuple[str, str, str]:
2424
"""
2525
Returns the group, version and kind of the object, if available.
2626
@@ -102,7 +102,7 @@ class K8sOpenAPIParser(OpenAPIParser):
102102
SCHEMA_OBJECT_TYPE = K8sSchemaObject
103103

104104
def __init__(
105-
self, source: Union[str, Path, list[Path], ParseResult], **kwargs: Any
105+
self, source: Union[str, Path, List[Path], ParseResult], **kwargs: Any
106106
):
107107
target_python_version = kwargs.pop(
108108
"target_python_version", _get_python_version()

tests/test_parser.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
from typing import Tuple
23
from unittest import TestCase
34

45
import pytest
@@ -19,7 +20,7 @@ def setUp(self):
1920
K8sOpenAPIExtractor(output_path=self.specs_path).extract()
2021
)
2122

22-
def _compare_with_expected(self, name: tuple[str, ...], result: str):
23+
def _compare_with_expected(self, name: Tuple[str, ...], result: str):
2324
expected_file = self.expected_path.joinpath(*name[4:]).with_suffix(".py")
2425

2526
with open(expected_file, "r") as f:

0 commit comments

Comments
 (0)