Skip to content

Commit 142c320

Browse files
authored
feat: Add support for python 3.9+
feat: Add support for python 3.9+
2 parents 8bcbfa0 + db3689b commit 142c320

8 files changed

+167
-92
lines changed

code_embedder/code_embedding.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from loguru import logger
24

35
from code_embedder.script_content_reader import ScriptContentReaderInterface
@@ -9,7 +11,7 @@ class CodeEmbedder:
911
def __init__(
1012
self,
1113
readme_paths: list[str],
12-
changed_files: list[str] | None,
14+
changed_files: Optional[list[str]],
1315
script_metadata_extractor: ScriptMetadataExtractorInterface,
1416
script_content_reader: ScriptContentReaderInterface,
1517
) -> None:
@@ -56,7 +58,7 @@ def _read_readme(self, readme_path: str) -> list[str]:
5658

5759
def _extract_scripts(
5860
self, readme_content: list[str], readme_path: str
59-
) -> list[ScriptMetadata] | None:
61+
) -> Optional[list[ScriptMetadata]]:
6062
scripts = self._script_metadata_extractor.extract(readme_content=readme_content)
6163
if not scripts:
6264
logger.debug(f"No script paths found in README in path {readme_path}. Skipping.")

code_embedder/script_content_reader.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ast
22
import re
3-
from typing import Protocol
3+
from typing import Optional, Protocol
44

55
from code_embedder.script_metadata import ScriptMetadata
66

@@ -83,7 +83,9 @@ def _extract_part(self, script: ScriptMetadata) -> str:
8383

8484
return "\n".join(lines[start:end])
8585

86-
def _extract_object_part(self, script: ScriptMetadata) -> tuple[int | None, int | None]:
86+
def _extract_object_part(
87+
self, script: ScriptMetadata
88+
) -> tuple[Optional[int], Optional[int]]:
8789
tree = ast.parse(script.content)
8890

8991
for node in ast.walk(tree):
@@ -100,8 +102,8 @@ def _extract_object_part(self, script: ScriptMetadata) -> tuple[int | None, int
100102
return None, None
101103

102104
def _extract_section_part(
103-
self, lines: list[str], section: str | None = None
104-
) -> tuple[int | None, int | None]:
105+
self, lines: list[str], section: Optional[str] = None
106+
) -> tuple[Optional[int], Optional[int]]:
105107
if not section:
106108
return None, None
107109

code_embedder/script_metadata.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
from typing import Literal
2+
from typing import Literal, Optional
33

44

55
@dataclass
@@ -8,5 +8,5 @@ class ScriptMetadata:
88
readme_end: int
99
path: str
1010
extraction_type: Literal["section", "object", "full"] = "full"
11-
extraction_part: str | None = None
11+
extraction_part: Optional[str] = None
1212
content: str = ""

code_embedder/script_metadata_extractor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from typing import Protocol
2+
from typing import Optional, Protocol
33

44
from code_embedder.script_metadata import ScriptMetadata
55

@@ -40,7 +40,7 @@ def _is_code_block_start(self, line: str) -> bool:
4040
def _is_code_block_end(self, line: str) -> bool:
4141
return line.strip() == self._code_block_end
4242

43-
def _start_new_block(self, line: str, row: int) -> dict | None:
43+
def _start_new_block(self, line: str, row: int) -> Optional[dict]:
4444
tag_items = line.split(self._path_separator)
4545
path = tag_items[1].strip()
4646
extraction_type = tag_items[2].strip() if len(tag_items) > 2 else "full"

poetry.lock

+146-75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "MIT"
1010
code-embedder = "code_embedder.main:app"
1111

1212
[tool.poetry.dependencies]
13-
python = "^3.11"
13+
python = "^3.9"
1414
loguru = "^0.7.2"
1515
typer-slim = "^0.13.0"
1616

@@ -27,5 +27,5 @@ build-backend = "poetry.core.masonry.api"
2727

2828
[tool.ruff]
2929
line-length = 95
30-
lint.select = ["E", "F", "I", "BLE", "UP", "FA"]
31-
target-version = "py311"
30+
lint.select = ["E", "F", "I", "BLE", "UP"]
31+
target-version = "py39"

tests/test_script_content_reader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal
1+
from typing import Literal, Optional
22

33
import pytest
44

@@ -9,7 +9,7 @@
99
def create_script_metadata(
1010
path: str,
1111
extraction_type: Literal["full", "section", "object"] = "full",
12-
extraction_part: str | None = None,
12+
extraction_part: Optional[str] = None,
1313
content: str = "",
1414
) -> ScriptMetadata:
1515
return ScriptMetadata(

tests/test_script_metadata_extractor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal
1+
from typing import Literal, Optional
22

33
import pytest
44

@@ -11,7 +11,7 @@ def create_script_metadata(
1111
readme_end: int,
1212
path: str,
1313
extraction_type: Literal["section", "object", "full"] = "full",
14-
extraction_part: str | None = None,
14+
extraction_part: Optional[str] = None,
1515
content: str = "",
1616
) -> ScriptMetadata:
1717
return ScriptMetadata(

0 commit comments

Comments
 (0)