Skip to content

Commit 198487b

Browse files
committed
format and lint all
1 parent 0e5ad41 commit 198487b

109 files changed

Lines changed: 2697 additions & 3204 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

codeflash/api/aiservice.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def optimize_code( # noqa: D417
129129
experiment_metadata: ExperimentMetadata | None = None,
130130
*,
131131
language: str = "python",
132-
language_version: str | None = None, # TODO:{claude} add language version to the language support and it should be cached
132+
language_version: str
133+
| None = None, # TODO:{claude} add language version to the language support and it should be cached
133134
module_system: str | None = None,
134135
is_async: bool = False,
135136
n_candidates: int = 5,
@@ -238,6 +239,7 @@ def optimize_python_code(
238239
is_async=is_async,
239240
n_candidates=n_candidates,
240241
)
242+
241243
def get_jit_rewritten_code( # noqa: D417
242244
self, source_code: str, trace_id: str
243245
) -> list[OptimizedCandidate]:
@@ -410,6 +412,7 @@ def optimize_code_refinement(self, request: list[AIServiceRefinerRequest]) -> li
410412
411413
Returns:
412414
List of refined optimization candidates
415+
413416
"""
414417
payload = []
415418
for opt in request:
@@ -727,7 +730,7 @@ def generate_regression_tests( # noqa: D417
727730
language: str = "python",
728731
language_version: str | None = None,
729732
module_system: str | None = None,
730-
is_numerical_code: bool | None = None, # noqa: FBT001
733+
is_numerical_code: bool | None = None,
731734
) -> tuple[str, str, str] | None:
732735
"""Generate regression tests for the given function by making a request to the Django endpoint.
733736

codeflash/api/schemas.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from dataclasses import dataclass, field
1616
from enum import Enum
17-
from pathlib import Path
1817
from typing import Any
1918

2019

@@ -192,10 +191,7 @@ def to_payload(self) -> dict[str, Any]:
192191
"""Convert to API payload dict, maintaining backward compatibility."""
193192
payload = {
194193
"source_code_being_tested": self.source_code,
195-
"function_to_optimize": {
196-
"function_name": self.function_name,
197-
"is_async": self.is_async,
198-
},
194+
"function_to_optimize": {"function_name": self.function_name, "is_async": self.is_async},
199195
"helper_function_names": self.helper_function_names,
200196
"module_path": self.module_path,
201197
"test_module_path": self.test_module_path,
@@ -243,24 +239,16 @@ def python_language_info(version: str | None = None) -> LanguageInfo:
243239

244240

245241
def javascript_language_info(
246-
module_system: ModuleSystem = ModuleSystem.COMMONJS,
247-
version: str = "ES2022",
242+
module_system: ModuleSystem = ModuleSystem.COMMONJS, version: str = "ES2022"
248243
) -> LanguageInfo:
249244
"""Create LanguageInfo for JavaScript."""
250245
ext = ".mjs" if module_system == ModuleSystem.ESM else ".js"
251246
return LanguageInfo(
252-
name="javascript",
253-
version=version,
254-
module_system=module_system,
255-
file_extension=ext,
256-
has_type_annotations=False,
247+
name="javascript", version=version, module_system=module_system, file_extension=ext, has_type_annotations=False
257248
)
258249

259250

260-
def typescript_language_info(
261-
module_system: ModuleSystem = ModuleSystem.ESM,
262-
version: str = "ES2022",
263-
) -> LanguageInfo:
251+
def typescript_language_info(module_system: ModuleSystem = ModuleSystem.ESM, version: str = "ES2022") -> LanguageInfo:
264252
"""Create LanguageInfo for TypeScript."""
265253
return LanguageInfo(
266254
name="typescript",

codeflash/cli_cmds/cmd_init.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,7 @@ def _customize_python_workflow_content(
15161516
codeflash_cmd += " --benchmark"
15171517
return optimize_yml_content.replace("{{ codeflash_command }}", codeflash_cmd)
15181518

1519+
15191520
# TODO:{claude} Refactor and move to support for language specific
15201521
def _customize_js_workflow_content(
15211522
optimize_yml_content: str,

codeflash/cli_cmds/console.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def code_print(
108108
function_name: Optional function name for LSP
109109
lsp_message_id: Optional LSP message ID
110110
language: Programming language for syntax highlighting ('python', 'javascript', 'typescript')
111+
111112
"""
112113
if is_LSP_enabled():
113114
lsp_log(
@@ -118,11 +119,7 @@ def code_print(
118119
from rich.syntax import Syntax
119120

120121
# Map codeflash language names to rich/pygments lexer names
121-
lexer_map = {
122-
"python": "python",
123-
"javascript": "javascript",
124-
"typescript": "typescript",
125-
}
122+
lexer_map = {"python": "python", "javascript": "javascript", "typescript": "typescript"}
126123
lexer = lexer_map.get(language, "python")
127124

128125
console.rule()

codeflash/cli_cmds/init_javascript.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""JavaScript/TypeScript project initialization for Codeflash."""
2+
23
# TODO:{claude} move to language support directory
34
from __future__ import annotations
45

@@ -125,8 +126,7 @@ def init_js_project(language: ProjectLanguage) -> None:
125126

126127
lang_panel = Panel(
127128
Text(
128-
f"📦 Detected {lang_name} project!\n\n"
129-
"I'll help you set up Codeflash for your project.",
129+
f"📦 Detected {lang_name} project!\n\nI'll help you set up Codeflash for your project.",
130130
style="cyan",
131131
justify="center",
132132
),
@@ -159,13 +159,13 @@ def init_js_project(language: ProjectLanguage) -> None:
159159
usage_table.add_column("Command", style="cyan")
160160
usage_table.add_column("Description", style="white")
161161

162-
usage_table.add_row(
163-
"codeflash --file <path-to-file> --function <function-name>", "Optimize a specific function"
164-
)
162+
usage_table.add_row("codeflash --file <path-to-file> --function <function-name>", "Optimize a specific function")
165163
usage_table.add_row("codeflash --all", "Optimize all functions in all files")
166164
usage_table.add_row("codeflash --help", "See all available options")
167165

168-
completion_message = f"⚡️ Codeflash is now set up for your {lang_name} project!\n\nYou can now run any of these commands:"
166+
completion_message = (
167+
f"⚡️ Codeflash is now set up for your {lang_name} project!\n\nYou can now run any of these commands:"
168+
)
169169

170170
if did_add_new_key:
171171
completion_message += (
@@ -265,10 +265,7 @@ def collect_js_setup_info(language: ProjectLanguage) -> JSSetupInfo:
265265
detection_table.add_row("Formatter", formatter_display)
266266

267267
detection_panel = Panel(
268-
Group(
269-
Text(f"Auto-detected settings for your {lang_name} project:\n", style="cyan"),
270-
detection_table,
271-
),
268+
Group(Text(f"Auto-detected settings for your {lang_name} project:\n", style="cyan"), detection_table),
272269
title="🔍 Auto-Detection Results",
273270
border_style="bright_blue",
274271
)
@@ -399,8 +396,7 @@ def _get_git_remote_for_setup() -> str:
399396

400397
git_panel = Panel(
401398
Text(
402-
"🔗 Configure Git Remote for Pull Requests.\n\n"
403-
"Codeflash will use this remote to create pull requests.",
399+
"🔗 Configure Git Remote for Pull Requests.\n\nCodeflash will use this remote to create pull requests.",
404400
style="blue",
405401
),
406402
title="🔗 Git Remote Setup",

codeflash/code_utils/config_js.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ def find_package_json(config_file: Path | None = None) -> Path | None:
206206

207207
return None
208208

209+
209210
def parse_package_json_config(package_json_path: Path) -> tuple[dict[str, Any], Path] | None:
210211
"""Parse codeflash config from package.json with auto-detection.
211212

codeflash/code_utils/deduplicate_code.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88

99
import hashlib
1010
import re
11-
from typing import TYPE_CHECKING
1211

1312
from codeflash.code_utils.normalizers import get_normalizer
1413
from codeflash.languages import current_language, is_python
1514

16-
if TYPE_CHECKING:
17-
pass
18-
1915

2016
def normalize_code(
2117
code: str,
@@ -35,6 +31,7 @@ def normalize_code(
3531
3632
Returns:
3733
Normalized code as string
34+
3835
"""
3936
if language is None:
4037
language = current_language().value
@@ -89,6 +86,7 @@ def get_code_fingerprint(code: str, language: str | None = None) -> str:
8986
9087
Returns:
9188
SHA-256 hash of normalized code
89+
9290
"""
9391
if language is None:
9492
language = current_language().value
@@ -112,6 +110,7 @@ def are_codes_duplicate(code1: str, code2: str, language: str | None = None) ->
112110
113111
Returns:
114112
True if codes are structurally identical (ignoring local variable names)
113+
115114
"""
116115
if language is None:
117116
language = current_language().value
@@ -127,8 +126,4 @@ def are_codes_duplicate(code1: str, code2: str, language: str | None = None) ->
127126

128127

129128
# Re-export for backward compatibility
130-
__all__ = [
131-
"normalize_code",
132-
"get_code_fingerprint",
133-
"are_codes_duplicate",
134-
]
129+
__all__ = ["are_codes_duplicate", "get_code_fingerprint", "normalize_code"]

codeflash/code_utils/normalizers/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222
from codeflash.code_utils.normalizers.javascript import JavaScriptNormalizer, TypeScriptNormalizer
2323
from codeflash.code_utils.normalizers.python import PythonNormalizer
2424

25-
if TYPE_CHECKING:
26-
pass
27-
2825
__all__ = [
2926
"CodeNormalizer",
30-
"PythonNormalizer",
3127
"JavaScriptNormalizer",
28+
"PythonNormalizer",
3229
"TypeScriptNormalizer",
3330
"get_normalizer",
3431
"get_normalizer_for_extension",
@@ -56,6 +53,7 @@ def get_normalizer(language: str) -> CodeNormalizer:
5653
5754
Raises:
5855
ValueError: If no normalizer exists for the language
56+
5957
"""
6058
language = language.lower()
6159

@@ -83,6 +81,7 @@ def get_normalizer_for_extension(extension: str) -> CodeNormalizer | None:
8381
8482
Returns:
8583
CodeNormalizer instance if found, None otherwise
84+
8685
"""
8786
extension = extension.lower()
8887
if not extension.startswith("."):
@@ -102,6 +101,7 @@ def register_normalizer(language: str, normalizer_class: type[CodeNormalizer]) -
102101
Args:
103102
language: Language name
104103
normalizer_class: CodeNormalizer subclass
104+
105105
"""
106106
_NORMALIZERS[language.lower()] = normalizer_class
107107
# Clear cached instance if it exists

codeflash/code_utils/normalizers/base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
They normalize variable names, remove comments/docstrings, and produce consistent output
55
that can be compared across different implementations of the same algorithm.
66
"""
7+
78
# TODO:{claude} move to base.py in language folder
89
from __future__ import annotations
910

1011
from abc import ABC, abstractmethod
11-
from typing import TYPE_CHECKING
12-
13-
if TYPE_CHECKING:
14-
pass
1512

1613

1714
class CodeNormalizer(ABC):
@@ -30,6 +27,7 @@ class CodeNormalizer(ABC):
3027
>>> code2 = "def foo(x): z = x + 1; return z"
3128
>>> normalizer.normalize(code1) == normalizer.normalize(code2)
3229
True
30+
3331
"""
3432

3533
@property
@@ -52,6 +50,7 @@ def normalize(self, code: str) -> str:
5250
5351
Returns:
5452
Normalized representation of the code
53+
5554
"""
5655
...
5756

@@ -66,6 +65,7 @@ def normalize_for_hash(self, code: str) -> str:
6665
6766
Returns:
6867
Normalized representation suitable for hashing
68+
6969
"""
7070
...
7171

@@ -78,6 +78,7 @@ def are_duplicates(self, code1: str, code2: str) -> bool:
7878
7979
Returns:
8080
True if codes are structurally identical
81+
8182
"""
8283
try:
8384
normalized1 = self.normalize_for_hash(code1)
@@ -94,6 +95,7 @@ def get_fingerprint(self, code: str) -> str:
9495
9596
Returns:
9697
SHA-256 hash of normalized code
98+
9799
"""
98100
import hashlib
99101

0 commit comments

Comments
 (0)