diff --git a/dspy/primitives/__init__.py b/dspy/primitives/__init__.py index c7cc2c0044..0fa160d260 100644 --- a/dspy/primitives/__init__.py +++ b/dspy/primitives/__init__.py @@ -1,8 +1,8 @@ from dspy.primitives import assertions from dspy.primitives.example import Example from dspy.primitives.module import BaseModule -from dspy.primitives.prediction import Prediction, Completions -from dspy.primitives.program import Program, Module +from dspy.primitives.prediction import Completions, Prediction +from dspy.primitives.program import Module, Program from dspy.primitives.python_interpreter import PythonInterpreter from dspy.primitives.tool import Tool diff --git a/dspy/primitives/example.py b/dspy/primitives/example.py index 0d809482ab..589e537480 100644 --- a/dspy/primitives/example.py +++ b/dspy/primitives/example.py @@ -104,5 +104,5 @@ def without(self, *keys): del copied[key] return copied - def toDict(self): + def toDict(self): # noqa: N802 return self._store.copy() diff --git a/dspy/primitives/module.py b/dspy/primitives/module.py index 13ebe8809f..3ddaf74d66 100644 --- a/dspy/primitives/module.py +++ b/dspy/primitives/module.py @@ -238,7 +238,7 @@ def load(self, path): path = Path(path) if path.suffix == ".json": - with open(path, "r") as f: + with open(path) as f: state = ujson.loads(f.read()) elif path.suffix == ".pkl": with open(path, "rb") as f: diff --git a/dspy/primitives/prediction.py b/dspy/primitives/prediction.py index b05b3857cf..670b816b28 100644 --- a/dspy/primitives/prediction.py +++ b/dspy/primitives/prediction.py @@ -26,7 +26,7 @@ def from_completions(cls, list_or_dict, signature=None): return obj def __repr__(self): - store_repr = ",\n ".join(f"{k}={repr(v)}" for k, v in self._store.items()) + store_repr = ",\n ".join(f"{k}={v!r}" for k, v in self._store.items()) if self._completions is None or len(self._completions) == 1: return f"Prediction(\n {store_repr}\n)" @@ -152,7 +152,7 @@ def __contains__(self, key): return key in self._completions def __repr__(self): - items_repr = ",\n ".join(f"{k}={repr(v)}" for k, v in self._completions.items()) + items_repr = ",\n ".join(f"{k}={v!r}" for k, v in self._completions.items()) return f"Completions(\n {items_repr}\n)" def __str__(self): diff --git a/dspy/primitives/python_interpreter.py b/dspy/primitives/python_interpreter.py index 7cb63bf98c..d96baa3635 100644 --- a/dspy/primitives/python_interpreter.py +++ b/dspy/primitives/python_interpreter.py @@ -1,8 +1,8 @@ import json +import os import subprocess from types import TracebackType from typing import Any, Dict, List, Optional -import os class InterpreterError(RuntimeError): @@ -155,4 +155,4 @@ def shutdown(self) -> None: self.deno_process.stdin.flush() self.deno_process.stdin.close() self.deno_process.wait() - self.deno_process = None \ No newline at end of file + self.deno_process = None diff --git a/dspy/primitives/tool.py b/dspy/primitives/tool.py index 3edea2d52c..63574a9b72 100644 --- a/dspy/primitives/tool.py +++ b/dspy/primitives/tool.py @@ -65,7 +65,7 @@ def foo(x: int, y: str = "hello"): self._parse_function(func, arg_desc) - def _parse_function(self, func: Callable, arg_desc: dict[str, str] = None): + def _parse_function(self, func: Callable, arg_desc: Optional[dict[str, str]] = None): """Helper method that parses a function to extract the name, description, and args. 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): self.desc = self.desc or desc self.args = self.args or args self.arg_types = self.arg_types or arg_types - self.has_kwargs = any([param.kind == param.VAR_KEYWORD for param in sig.parameters.values()]) + self.has_kwargs = any(param.kind == param.VAR_KEYWORD for param in sig.parameters.values()) def _validate_and_parse_args(self, **kwargs): # Validate the args value comply to the json schema.