Skip to content

Commit 7e3f6cd

Browse files
committedNov 24, 2024
fix: Replace type pipe with Optional
1 parent 5ad2156 commit 7e3f6cd

6 files changed

+18
-14
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 = ""

‎pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -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)
Failed to load comments.