Skip to content

Commit b87eb7e

Browse files
committed
lint and update deps
1 parent aedaac2 commit b87eb7e

File tree

7 files changed

+373
-354
lines changed

7 files changed

+373
-354
lines changed

patchwork/common/utils/input_parsing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import json
44
from collections.abc import Iterable, Mapping
5-
from shutil import posix
65

76
from typing_extensions import AnyStr, Union
87

@@ -72,7 +71,8 @@ def parse_to_list(
7271
rv.append(stripped_value)
7372
return rv
7473

75-
def parse_to_dict(possible_dict, limit = -1):
74+
75+
def parse_to_dict(possible_dict, limit=-1):
7676
if possible_dict is None and limit == 0:
7777
return None
7878

patchwork/steps/FixIssue/FixIssue.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import difflib
21
import re
32
from pathlib import Path
43
from typing import Any, Optional
54

6-
from git import Repo, InvalidGitRepositoryError
7-
from patchwork.logger import logger
5+
from git import InvalidGitRepositoryError, Repo
86
from openai.types.chat import ChatCompletionMessageParam
97

108
from patchwork.common.client.llm.aio import AioLlmClient
@@ -15,6 +13,7 @@
1513
AnalyzeImplementStrategy,
1614
)
1715
from patchwork.common.tools import CodeEditTool, Tool
16+
from patchwork.logger import logger
1817
from patchwork.step import Step
1918
from patchwork.steps.FixIssue.typed import FixIssueInputs, FixIssueOutputs
2019

@@ -100,7 +99,7 @@ def is_stop(self, messages: list[ChatCompletionMessageParam]) -> bool:
10099
class FixIssue(Step, input_class=FixIssueInputs, output_class=FixIssueOutputs):
101100
def __init__(self, inputs):
102101
"""Initialize the FixIssue step.
103-
102+
104103
Args:
105104
inputs: Dictionary containing input parameters including:
106105
- base_path: Optional path to the repository root
@@ -145,12 +144,12 @@ def __init__(self, inputs):
145144

146145
def run(self):
147146
"""Execute the FixIssue step.
148-
147+
149148
This method:
150149
1. Executes the multi-turn LLM conversation to analyze and fix the issue
151150
2. Tracks file modifications made by the CodeEditTool
152151
3. Generates in-memory diffs for all modified files
153-
152+
154153
Returns:
155154
dict: Dictionary containing list of modified files with their diffs
156155
"""
@@ -162,8 +161,7 @@ def run(self):
162161
if not isinstance(tool, CodeEditTool):
163162
continue
164163
tool_modified_files = [
165-
dict(path=str(file_path.relative_to(cwd)), diff="")
166-
for file_path in tool.tool_records["modified_files"]
164+
dict(path=str(file_path.relative_to(cwd)), diff="") for file_path in tool.tool_records["modified_files"]
167165
]
168166
modified_files.extend(tool_modified_files)
169167

@@ -174,7 +172,7 @@ def run(self):
174172
file = modified_file["path"]
175173
try:
176174
# Try to get the diff using git
177-
diff = self.repo.git.diff('HEAD', file)
175+
diff = self.repo.git.diff("HEAD", file)
178176
modified_file["diff"] = diff or ""
179177
except Exception as e:
180178
# Git-specific errors (untracked files, etc) - keep empty diff

patchwork/steps/FixIssue/typed.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing_extensions import Annotated, Dict, List, TypedDict
1+
from typing_extensions import Annotated, List, TypedDict
22

33
from patchwork.common.constants import TOKEN_URL
44
from patchwork.common.utils.step_typing import StepTypeConfig
@@ -37,19 +37,21 @@ class FixIssueInputs(__FixIssueRequiredInputs, total=False):
3737

3838
class ModifiedFile(TypedDict):
3939
"""Represents a file that has been modified by the FixIssue step.
40-
40+
4141
Attributes:
4242
path: The relative path to the modified file from the repository root
4343
diff: A unified diff string showing the changes made to the file.
4444
Generated using Python's difflib to compare the original and
4545
modified file contents in memory.
46-
46+
4747
Note:
4848
The diff is generated by comparing file contents before and after
4949
modifications, without relying on version control systems.
5050
"""
51+
5152
path: str
5253
diff: str
5354

55+
5456
class FixIssueOutputs(TypedDict):
5557
modified_files: List[ModifiedFile]

patchwork/steps/ModifyCode/ModifyCode.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def save_file_contents(file_path: str | Path, content: str) -> None:
1111
"""Utility function to save content to a file.
12-
12+
1313
Args:
1414
file_path: Path to the file to save content to (str or Path)
1515
content: Content to write to the file
@@ -47,7 +47,7 @@ def replace_code_in_file(
4747
new_code: str,
4848
) -> None:
4949
"""Replace code in a file at the specified line range.
50-
50+
5151
Args:
5252
file_path: Path to the file to modify (str or Path)
5353
start_line: Starting line number (1-based)
@@ -109,38 +109,36 @@ def run(self) -> dict:
109109
try:
110110
# Store original content in memory
111111
original_content = file_path.read_text() if file_path.exists() else ""
112-
112+
113113
# Apply the changes
114114
replace_code_in_file(file_path, start_line, end_line, new_code)
115-
115+
116116
# Read modified content
117117
current_content = file_path.read_text() if file_path.exists() else ""
118-
118+
119119
# Generate unified diff
120120
fromfile = f"a/{file_path}"
121121
tofile = f"b/{file_path}"
122-
diff = "".join(difflib.unified_diff(
123-
original_content.splitlines(keepends=True),
124-
current_content.splitlines(keepends=True),
125-
fromfile=fromfile,
126-
tofile=tofile
127-
))
128-
122+
diff = "".join(
123+
difflib.unified_diff(
124+
original_content.splitlines(keepends=True),
125+
current_content.splitlines(keepends=True),
126+
fromfile=fromfile,
127+
tofile=tofile,
128+
)
129+
)
130+
129131
if not diff and new_code: # If no diff but we have new code (new file)
130132
diff = f"+++ {file_path}\n{new_code}"
131133
except (OSError, IOError) as e:
132134
logger.warning(f"Failed to generate diff for {file_path}: {str(e)}")
133135
# Still proceed with the modification even if diff generation fails
134136
replace_code_in_file(file_path, start_line, end_line, new_code)
135137
diff = f"+++ {file_path}\n{new_code}" # Use new code as diff on error
136-
138+
137139
# Create the modified code file dictionary
138140
modified_code_file = dict(
139-
path=str(file_path),
140-
start_line=start_line,
141-
end_line=end_line,
142-
diff=diff,
143-
**extracted_response
141+
path=str(file_path), start_line=start_line, end_line=end_line, diff=diff, **extracted_response
144142
)
145143
modified_code_files.append(modified_code_file)
146144

patchwork/steps/ModifyCode/typed.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@ class ModifyCodeOutputs(TypedDict):
1212

1313
class ModifiedCodeFile(TypedDict, total=False):
1414
"""Represents a file that has been modified by the ModifyCode step.
15-
15+
1616
Attributes:
1717
path: The path to the modified file
1818
start_line: The starting line number of the modification (1-based)
1919
end_line: The ending line number of the modification (1-based)
2020
diff: A unified diff string showing the changes made to the file.
2121
Generated using Python's difflib for in-memory comparison
2222
of original and modified file contents.
23-
23+
2424
Note:
2525
The diff field is generated using difflib.unified_diff() to compare
2626
the original and modified file contents in memory, ensuring efficient
2727
and secure diff generation.
2828
"""
29+
2930
path: str
3031
start_line: int
3132
end_line: int

0 commit comments

Comments
 (0)