Skip to content

Commit c1b5754

Browse files
Fix coding style in dspy/primitives (#8180)
* enable style check * update rules * allow wildcard imports * fix style
1 parent ab5984d commit c1b5754

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

dspy/primitives/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from dspy.primitives import assertions
22
from dspy.primitives.example import Example
33
from dspy.primitives.module import BaseModule
4-
from dspy.primitives.prediction import Prediction, Completions
5-
from dspy.primitives.program import Program, Module
4+
from dspy.primitives.prediction import Completions, Prediction
5+
from dspy.primitives.program import Module, Program
66
from dspy.primitives.python_interpreter import PythonInterpreter
77
from dspy.primitives.tool import Tool
88

dspy/primitives/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ def without(self, *keys):
104104
del copied[key]
105105
return copied
106106

107-
def toDict(self):
107+
def toDict(self): # noqa: N802
108108
return self._store.copy()

dspy/primitives/module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def load(self, path):
238238
path = Path(path)
239239

240240
if path.suffix == ".json":
241-
with open(path, "r") as f:
241+
with open(path) as f:
242242
state = ujson.loads(f.read())
243243
elif path.suffix == ".pkl":
244244
with open(path, "rb") as f:

dspy/primitives/prediction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def from_completions(cls, list_or_dict, signature=None):
2626
return obj
2727

2828
def __repr__(self):
29-
store_repr = ",\n ".join(f"{k}={repr(v)}" for k, v in self._store.items())
29+
store_repr = ",\n ".join(f"{k}={v!r}" for k, v in self._store.items())
3030

3131
if self._completions is None or len(self._completions) == 1:
3232
return f"Prediction(\n {store_repr}\n)"
@@ -152,7 +152,7 @@ def __contains__(self, key):
152152
return key in self._completions
153153

154154
def __repr__(self):
155-
items_repr = ",\n ".join(f"{k}={repr(v)}" for k, v in self._completions.items())
155+
items_repr = ",\n ".join(f"{k}={v!r}" for k, v in self._completions.items())
156156
return f"Completions(\n {items_repr}\n)"
157157

158158
def __str__(self):

dspy/primitives/python_interpreter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import json
2+
import os
23
import subprocess
34
from types import TracebackType
45
from typing import Any, Dict, List, Optional
5-
import os
66

77

88
class InterpreterError(RuntimeError):
@@ -155,4 +155,4 @@ def shutdown(self) -> None:
155155
self.deno_process.stdin.flush()
156156
self.deno_process.stdin.close()
157157
self.deno_process.wait()
158-
self.deno_process = None
158+
self.deno_process = None

dspy/primitives/tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def foo(x: int, y: str = "hello"):
6565

6666
self._parse_function(func, arg_desc)
6767

68-
def _parse_function(self, func: Callable, arg_desc: dict[str, str] = None):
68+
def _parse_function(self, func: Callable, arg_desc: Optional[dict[str, str]] = None):
6969
"""Helper method that parses a function to extract the name, description, and args.
7070
7171
This is a helper function that automatically infers the name, description, and args of the tool from the
@@ -107,7 +107,7 @@ def _parse_function(self, func: Callable, arg_desc: dict[str, str] = None):
107107
self.desc = self.desc or desc
108108
self.args = self.args or args
109109
self.arg_types = self.arg_types or arg_types
110-
self.has_kwargs = any([param.kind == param.VAR_KEYWORD for param in sig.parameters.values()])
110+
self.has_kwargs = any(param.kind == param.VAR_KEYWORD for param in sig.parameters.values())
111111

112112
def _validate_and_parse_args(self, **kwargs):
113113
# Validate the args value comply to the json schema.

0 commit comments

Comments
 (0)