Skip to content
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

Add ruff for shared mutable defaults (B) #1938

Merged
merged 11 commits into from
May 23, 2024
3 changes: 2 additions & 1 deletion agenthub/SWE_agent/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ def STEP_PROMPT(task, file, line_num):
""".strip()


def unpack_dict(data: dict, restrict: list[str] = []):
def unpack_dict(data: dict, restrict: list[str] | None = None):
lines = []
restrict = [] if restrict is None else restrict
for key, value in data.items():
if key in restrict:
continue
Expand Down
3 changes: 1 addition & 2 deletions agenthub/micro/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
promptFile = base + '/prompt.md'
agentFile = base + '/agent.yaml'
if not os.path.isfile(promptFile) or not os.path.isfile(agentFile):
raise Exception(
f'Missing prompt or agent file in {base}. Please create them.')
raise Exception(f'Missing prompt or agent file in {base}. Please create them.')
with open(promptFile, 'r') as f:
prompt = f.read()
with open(agentFile, 'r') as f:
Expand Down
5 changes: 4 additions & 1 deletion agenthub/monologue_agent/utils/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_summarize_monologue_prompt(thoughts: list[dict]):
def get_request_action_prompt(
task: str,
thoughts: list[dict],
background_commands_obs: list[CmdOutputObservation] = [],
background_commands_obs: list[CmdOutputObservation] | None = None,
):
"""
Gets the action prompt formatted with appropriate values.
Expand All @@ -122,6 +122,9 @@ def get_request_action_prompt(
- str: Formatted prompt string with hint, task, monologue, and background included
"""

if background_commands_obs is None:
background_commands_obs = []

hint = ''
if len(thoughts) > 0:
latest_thought = thoughts[-1]
Expand Down
7 changes: 7 additions & 0 deletions dev_config/python/ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ select = [
"F",
"I",
"Q",
"B",
]

ignore = [
"E501",
"B003",
"B007",
"B009",
"B010",
"B904",
"B018",
]

[lint.flake8-quotes]
Expand Down
7 changes: 4 additions & 3 deletions opendevin/controller/state/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
parent: 'Task',
goal: str,
state: str = OPEN_STATE,
subtasks: list = [],
subtasks: list | None = None,
):
"""Initializes a new instance of the Task class.

Expand All @@ -39,13 +39,13 @@ def __init__(
state: The initial state of the task.
subtasks: A list of subtasks associated with this task.
"""
self.subtasks = [] if subtasks is None else subtasks
if parent.id:
self.id = parent.id + '.' + str(len(parent.subtasks))
else:
self.id = str(len(parent.subtasks))
self.parent = parent
self.goal = goal
self.subtasks = []
for subtask in subtasks or []:
if isinstance(subtask, Task):
self.subtasks.append(subtask)
Expand Down Expand Up @@ -190,14 +190,15 @@ def get_task_by_id(self, id: str) -> Task:
task = task.subtasks[part]
return task

def add_subtask(self, parent_id: str, goal: str, subtasks: list = []):
def add_subtask(self, parent_id: str, goal: str, subtasks: list | None = None):
"""Adds a subtask to a parent task.

Args:
parent_id: The ID of the parent task.
goal: The goal of the subtask.
subtasks: A list of subtasks associated with the new subtask.
"""
subtasks = subtasks or []
parent = self.get_task_by_id(parent_id)
child = Task(parent=parent, goal=goal, subtasks=subtasks)
parent.subtasks.append(child)
Expand Down
3 changes: 2 additions & 1 deletion opendevin/core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def get_console_handler():
return console_handler


def get_file_handler(log_dir=os.path.join(os.getcwd(), 'logs')):
def get_file_handler(log_dir=None):
"""
Returns a file handler for logging.
"""
log_dir = os.path.join(os.getcwd(), 'logs') if log_dir is None else log_dir
os.makedirs(log_dir, exist_ok=True)
timestamp = datetime.now().strftime('%Y-%m-%d')
file_name = f'opendevin_{timestamp}.log'
Expand Down
Loading