Skip to content

Commit 32a8001

Browse files
committed
fix types for python 3.9
1 parent 2c1314d commit 32a8001

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

codeflash/discovery/functions_to_optimize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ class FunctionToOptimize:
126126
function_name: str
127127
file_path: Path
128128
parents: list[FunctionParent] # list[ClassDef | FunctionDef | AsyncFunctionDef]
129-
starting_line: int | None = None
130-
ending_line: int | None = None
129+
starting_line: Optional[int] = None
130+
ending_line: Optional[int] = None
131131

132132
@property
133133
def top_level_parent_name(self) -> str:

codeflash/models/models.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from collections import defaultdict
4-
from typing import TYPE_CHECKING, Optional
4+
from typing import TYPE_CHECKING
55

66
from rich.tree import Tree
77

@@ -16,7 +16,7 @@
1616
from enum import Enum, IntEnum
1717
from pathlib import Path
1818
from re import Pattern
19-
from typing import Annotated, cast
19+
from typing import Annotated, Optional, cast
2020

2121
from jedi.api.classes import Name
2222
from pydantic import AfterValidator, BaseModel, ConfigDict, Field
@@ -77,10 +77,10 @@ class BestOptimization(BaseModel):
7777
candidate: OptimizedCandidate
7878
helper_functions: list[FunctionSource]
7979
runtime: int
80-
replay_performance_gain: dict[BenchmarkKey, float] | None = None
80+
replay_performance_gain: Optional[dict[BenchmarkKey, float]] = None
8181
winning_behavioral_test_results: TestResults
8282
winning_benchmarking_test_results: TestResults
83-
winning_replay_benchmarking_test_results: TestResults | None = None
83+
winning_replay_benchmarking_test_results: Optional[TestResults] = None
8484

8585

8686
@dataclass(frozen=True)
@@ -175,7 +175,7 @@ class OptimizedCandidateResult(BaseModel):
175175
best_test_runtime: int
176176
behavior_test_results: TestResults
177177
benchmarking_test_results: TestResults
178-
replay_benchmarking_test_results: dict[BenchmarkKey, TestResults] | None = None
178+
replay_benchmarking_test_results: Optional[dict[BenchmarkKey, TestResults]] = None
179179
optimization_candidate_index: int
180180
total_candidate_timing: int
181181

@@ -195,10 +195,10 @@ class GeneratedTestsList(BaseModel):
195195
class TestFile(BaseModel):
196196
instrumented_behavior_file_path: Path
197197
benchmarking_file_path: Path = None
198-
original_file_path: Path | None = None
199-
original_source: str | None = None
198+
original_file_path: Optional[Path] = None
199+
original_source: Optional[str] = None
200200
test_type: TestType
201-
tests_in_file: list[TestsInFile] | None = None
201+
tests_in_file: Optional[list[TestsInFile]] = None
202202

203203

204204
class TestFiles(BaseModel):
@@ -241,13 +241,13 @@ def __len__(self) -> int:
241241

242242
class OptimizationSet(BaseModel):
243243
control: list[OptimizedCandidate]
244-
experiment: list[OptimizedCandidate] | None
244+
experiment: Optional[list[OptimizedCandidate]]
245245

246246

247247
@dataclass(frozen=True)
248248
class TestsInFile:
249249
test_file: Path
250-
test_class: str | None
250+
test_class: Optional[str]
251251
test_function: str
252252
test_type: TestType
253253

@@ -280,10 +280,10 @@ class FunctionParent:
280280
class OriginalCodeBaseline(BaseModel):
281281
behavioral_test_results: TestResults
282282
benchmarking_test_results: TestResults
283-
replay_benchmarking_test_results: dict[BenchmarkKey, TestResults] | None = None
283+
replay_benchmarking_test_results: Optional[dict[BenchmarkKey, TestResults]] = None
284284
line_profile_results: dict
285285
runtime: int
286-
coverage_results: CoverageData | None
286+
coverage_results: Optional[CoverageData]
287287

288288

289289
class CoverageStatus(Enum):
@@ -302,7 +302,7 @@ class CoverageData:
302302
graph: dict[str, dict[str, Collection[object]]]
303303
code_context: CodeOptimizationContext
304304
main_func_coverage: FunctionCoverage
305-
dependent_func_coverage: FunctionCoverage | None
305+
dependent_func_coverage: Optional[FunctionCoverage]
306306
status: CoverageStatus
307307
blank_re: Pattern[str] = re.compile(r"\s*(#|$)")
308308
else_re: Pattern[str] = re.compile(r"\s*else\s*:\s*(#|$)")
@@ -410,10 +410,10 @@ def to_name(self) -> str:
410410
@dataclass(frozen=True)
411411
class InvocationId:
412412
test_module_path: str # The fully qualified name of the test module
413-
test_class_name: str | None # The name of the class where the test is defined
414-
test_function_name: str | None # The name of the test_function. Does not include the components of the file_name
413+
test_class_name: Optional[str] # The name of the class where the test is defined
414+
test_function_name: Optional[str] # The name of the test_function. Does not include the components of the file_name
415415
function_getting_tested: str
416-
iteration_id: str | None
416+
iteration_id: Optional[str]
417417

418418
# test_module_path:TestSuiteClass.test_function_name:function_tested:iteration_id
419419
def id(self) -> str:
@@ -449,13 +449,13 @@ class FunctionTestInvocation:
449449
id: InvocationId # The fully qualified name of the function invocation (id)
450450
file_name: Path # The file where the test is defined
451451
did_pass: bool # Whether the test this function invocation was part of, passed or failed
452-
runtime: int | None # Time in nanoseconds
452+
runtime: Optional[int] # Time in nanoseconds
453453
test_framework: str # unittest or pytest
454454
test_type: TestType
455-
return_value: object | None # The return value of the function invocation
456-
timed_out: bool | None
457-
verification_type: str | None = VerificationType.FUNCTION_CALL
458-
stdout: str | None = None
455+
return_value: Optional[object] # The return value of the function invocation
456+
timed_out: Optional[bool]
457+
verification_type: Optional[str] = VerificationType.FUNCTION_CALL
458+
stdout: Optional[str] = None
459459

460460
@property
461461
def unique_invocation_loop_id(self) -> str:

0 commit comments

Comments
 (0)