Skip to content

Commit b30c55c

Browse files
fix style (#8337)
1 parent a304b13 commit b30c55c

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

dspy/predict/code_act.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import inspect
2-
from typing import Callable, Union, Type, Optional
32
import logging
43
from inspect import Signature
4+
from typing import Callable, Optional, Type, Union
55

66
import dspy
77
from dspy.adapters.types.tool import Tool
@@ -68,7 +68,7 @@ def factorial(n):
6868
self.extractor = dspy.ChainOfThought(extract_signature)
6969
# It will raises exception when dspy cannot find available deno instance by now.
7070
self.interpreter = interpreter or PythonInterpreter()
71-
71+
7272
def _build_instructions(self, signature, tools):
7373
instructions = [f"{signature.instructions}\n"] if signature.instructions else []
7474
inputs = ", ".join([f"`{k}`" for k in signature.input_fields.keys()])

dspy/predict/program_of_thought.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import logging
33
import re
4-
from typing import Type, Union, Optional
4+
from typing import Optional, Type, Union
55

66
import dspy
77
from dspy.primitives.program import Module

dspy/primitives/python_interpreter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import json
22
import os
33
import subprocess
4+
from os import PathLike
45
from types import TracebackType
56
from typing import Any, Dict, List, Optional, Union
6-
from os import PathLike
77

88

99
class InterpreterError(RuntimeError):
@@ -66,7 +66,7 @@ def __init__(
6666
args.append(f"--allow-net={','.join(str(x) for x in self.enable_network_access)}")
6767
if self.enable_write_paths:
6868
args.append(f"--allow-write={','.join(str(x) for x in self.enable_write_paths)}")
69-
69+
7070
args.append(self._get_runner_path())
7171

7272
# For runner.js to load in env vars

dspy/teleprompt/mipro_optimizer_v2.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@
55
import textwrap
66
import time
77
from collections import defaultdict
8-
from typing import (TYPE_CHECKING, Any, Callable, Dict, List, Literal,
9-
Optional, Tuple)
8+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Literal, Optional, Tuple
109

1110
import numpy as np
1211

1312
import dspy
1413
from dspy.evaluate.evaluate import Evaluate
1514
from dspy.propose import GroundedProposer
1615
from dspy.teleprompt.teleprompt import Teleprompter
17-
from dspy.teleprompt.utils import (create_minibatch,
18-
create_n_fewshot_demo_sets,
19-
eval_candidate_program,
20-
get_program_with_highest_avg_score,
21-
get_signature, print_full_program,
22-
save_candidate_program, set_signature)
16+
from dspy.teleprompt.utils import (
17+
create_minibatch,
18+
create_n_fewshot_demo_sets,
19+
eval_candidate_program,
20+
get_program_with_highest_avg_score,
21+
get_signature,
22+
print_full_program,
23+
save_candidate_program,
24+
set_signature,
25+
)
2326

2427
if TYPE_CHECKING:
2528
import optuna

tests/adapters/test_base_type.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import dspy
21
from typing import Optional
2+
33
import pydantic
44

5+
import dspy
6+
57

68
def test_basic_extract_custom_type_from_annotation():
79
class Event(dspy.BaseType):

tests/primitives/test_python_interpreter.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import os
12
import random
23
import shutil
3-
import os
4+
45
import pytest
6+
57
from dspy.primitives.python_interpreter import InterpreterError, PythonInterpreter
68

79
# This test suite requires deno to be installed. Please install deno following https://docs.deno.com/runtime/getting_started/installation/
@@ -60,7 +62,7 @@ def test_final_answer_trick():
6062

6163
# They should maintain the same order
6264
assert result == ["The result is", token], "The returned results are differ, `final_answer` trick doesn't work"
63-
65+
6466
def test_enable_env_vars_flag():
6567
os.environ["FOO_TEST_ENV"] = "test_value"
6668

@@ -84,7 +86,7 @@ def test_read_file_access_control(tmp_path):
8486

8587
with PythonInterpreter(enable_read_paths=[str(testfile_path)]) as interpreter:
8688
code = (
87-
f"with open({repr(virtual_path)}, 'r') as f:\n"
89+
f"with open({virtual_path!r}, 'r') as f:\n"
8890
f" data = f.read()\n"
8991
f"data"
9092
)
@@ -94,7 +96,7 @@ def test_read_file_access_control(tmp_path):
9496
with PythonInterpreter(enable_read_paths=None) as interpreter:
9597
code = (
9698
f"try:\n"
97-
f" with open({repr(virtual_path)}, 'r') as f:\n"
99+
f" with open({virtual_path!r}, 'r') as f:\n"
98100
f" data = f.read()\n"
99101
f"except Exception as e:\n"
100102
f" data = str(e)\n"
@@ -110,7 +112,7 @@ def test_enable_write_flag(tmp_path):
110112
with PythonInterpreter(enable_write_paths=None) as interpreter:
111113
code = (
112114
f"try:\n"
113-
f" with open({repr(virtual_path)}, 'w') as f:\n"
115+
f" with open({virtual_path!r}, 'w') as f:\n"
114116
f" f.write('blocked')\n"
115117
f" result = 'wrote'\n"
116118
f"except Exception as e:\n"
@@ -122,27 +124,27 @@ def test_enable_write_flag(tmp_path):
122124

123125
with PythonInterpreter(enable_write_paths=[str(testfile_path)]) as interpreter:
124126
code = (
125-
f"with open({repr(virtual_path)}, 'w') as f:\n"
127+
f"with open({virtual_path!r}, 'w') as f:\n"
126128
f" f.write('allowed')\n"
127129
f"'ok'"
128130
)
129131
result = interpreter.execute(code)
130132
assert result == "ok", "Test file should be writable with enable_write_paths"
131133
assert testfile_path.exists()
132-
with open(testfile_path, "r") as f:
134+
with open(testfile_path) as f:
133135
assert f.read() == "allowed", "Test file outputs should match content written during execution"
134-
136+
135137
with open(testfile_path, "w") as f:
136138
f.write("original_content")
137139
with PythonInterpreter(enable_write_paths=[str(testfile_path)], sync_files=False) as interpreter:
138140
code = (
139-
f"with open({repr(virtual_path)}, 'w') as f:\n"
141+
f"with open({virtual_path!r}, 'w') as f:\n"
140142
f" f.write('should_not_sync')\n"
141143
f"'done_no_sync'"
142144
)
143145
result = interpreter.execute(code)
144146
assert result == "done_no_sync"
145-
with open(testfile_path, "r") as f:
147+
with open(testfile_path) as f:
146148
assert f.read() == "original_content", "File should not be changed when sync_files is False"
147149

148150

@@ -153,7 +155,7 @@ def test_enable_net_flag():
153155
with PythonInterpreter(enable_network_access=None) as interpreter:
154156
code = (
155157
"import js\n"
156-
f"resp = await js.fetch({repr(test_url)})\n"
158+
f"resp = await js.fetch({test_url!r})\n"
157159
"resp.status"
158160
)
159161
with pytest.raises(InterpreterError, match="PythonError"):
@@ -162,7 +164,7 @@ def test_enable_net_flag():
162164
with PythonInterpreter(enable_network_access=["example.com"]) as interpreter:
163165
code = (
164166
"import js\n"
165-
f"resp = await js.fetch({repr(test_url)})\n"
167+
f"resp = await js.fetch({test_url!r})\n"
166168
"resp.status"
167169
)
168170
result = interpreter.execute(code)

0 commit comments

Comments
 (0)