Skip to content

Fix coding style in dspy/primitives #8180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dspy/primitives/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion dspy/primitives/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion dspy/primitives/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions dspy/primitives/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions dspy/primitives/python_interpreter.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
self.deno_process = None
4 changes: 2 additions & 2 deletions dspy/primitives/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down