Skip to content

Commit f68f336

Browse files
Fix type errors in code_integrity_analyzer.py, analysis.py, diff_analyzer.py, commit_analyzer.py, and swe_harness_agent.py
1 parent 34fe5db commit f68f336

File tree

5 files changed

+57
-80
lines changed

5 files changed

+57
-80
lines changed

codegen-on-oss/codegen_on_oss/analysis/analysis.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747

4848
# Import from other analysis modules
4949
from graph_sitter.codebase.codebase_context import CodebaseContext
50-
from codegen_on_oss.analysis.commit_analysis import (
50+
from codegen_on_oss.analysis.commit_analyzer import (
51+
CommitAnalyzer,
5152
CommitAnalysisResult,
5253
)
53-
from codegen_on_oss.analysis.commit_analyzer import CommitAnalyzer
5454

5555
# Import new analysis modules
5656
from codegen_on_oss.analysis.diff_analyzer import DiffAnalyzer
@@ -566,7 +566,16 @@ def analyze_commit(self, commit_codebase: Codebase) -> CommitAnalysisResult:
566566
analyzer = CommitAnalyzer(original_codebase=self.codebase, commit_codebase=commit_codebase)
567567

568568
# Analyze the commit
569-
return analyzer.analyze_commit()
569+
results = analyzer.analyze_commit()
570+
return CommitAnalysisResult(
571+
is_properly_implemented=results["quality_assessment"]["is_properly_implemented"],
572+
issues=[], # Convert issues from dict to CommitAnalysisIssue objects
573+
metrics_diff=results["metrics_diff"],
574+
files_added=results["files_added"],
575+
files_modified=results["files_modified"],
576+
files_removed=results["files_removed"],
577+
summary=None, # Will be generated when get_summary is called
578+
)
570579

571580
@classmethod
572581
def analyze_commit_from_repo_and_commit(

codegen-on-oss/codegen_on_oss/analysis/code_integrity_analyzer.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ def _analyze_functions(self, functions: List[Function]) -> List[Dict[str, Any]]:
394394
)
395395

396396
# Check for too many parameters
397-
if len(func.parameters) > self.config["max_function_parameters"]: # Arbitrary threshold
397+
max_params = int(str(self.config["max_function_parameters"]))
398+
if len(func.parameters) > max_params: # Arbitrary threshold
398399
errors.append(
399400
{
400401
"type": "function_error",
@@ -408,8 +409,9 @@ def _analyze_functions(self, functions: List[Function]) -> List[Dict[str, Any]]:
408409
)
409410

410411
# Check for too many return statements
412+
max_returns = int(str(self.config["max_function_returns"]))
411413
if (
412-
len(func.return_statements) > self.config["max_function_returns"]
414+
len(func.return_statements) > max_returns
413415
): # Arbitrary threshold
414416
errors.append(
415417
{
@@ -465,7 +467,8 @@ def _analyze_classes(self, classes: List[Class]) -> List[Dict[str, Any]]:
465467
)
466468

467469
# Check for too many methods
468-
if len(cls.methods) > self.config["max_class_methods"]: # Arbitrary threshold
470+
max_methods = int(str(self.config["max_class_methods"]))
471+
if len(cls.methods) > max_methods: # Arbitrary threshold
469472
errors.append(
470473
{
471474
"type": "class_error",
@@ -478,7 +481,8 @@ def _analyze_classes(self, classes: List[Class]) -> List[Dict[str, Any]]:
478481
)
479482

480483
# Check for too many attributes
481-
if len(cls.attributes) > self.config["max_class_attributes"]: # Arbitrary threshold
484+
max_attrs = int(str(self.config["max_class_attributes"]))
485+
if len(cls.attributes) > max_attrs: # Arbitrary threshold
482486
errors.append(
483487
{
484488
"type": "class_error",
@@ -664,7 +668,8 @@ def _analyze_complexity(self, functions: List[Function]) -> List[Dict[str, Any]]
664668
complexity += 1
665669

666670
# Check if complexity exceeds threshold
667-
if complexity > self.config["max_function_complexity"]:
671+
max_complexity = int(str(self.config["max_function_complexity"]))
672+
if complexity > max_complexity:
668673
errors.append(
669674
{
670675
"type": "complexity_error",

codegen-on-oss/codegen_on_oss/analysis/commit_analyzer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ def analyze_commit_from_repo_and_commit(
529529
],
530530
metrics_diff=results["metrics_diff"],
531531
files_added=results["files_added"],
532-
files_modified=results["files_modified"],
533-
files_removed=results["files_removed"],
532+
files_modified=files_modified,
533+
files_removed=files_removed,
534534
summary=None, # Will be generated when get_summary is called
535535
)
536536

@@ -601,5 +601,3 @@ def analyze_commit_from_paths(
601601
files_removed=files_removed,
602602
summary=None, # Will be generated when get_summary is called
603603
)
604-
"""
605-

codegen-on-oss/codegen_on_oss/analysis/diff_analyzer.py

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -560,57 +560,27 @@ def format_summary_text(self) -> str:
560560
def perform_detailed_analysis(self) -> Dict[str, Any]:
561561
"""Perform a detailed analysis of the differences between the two snapshots."""
562562
results = self._initialize_analysis_results()
563-
results.update(self._analyze_files_and_functions())
564-
results.update(self._analyze_complexity())
565563
results.update(self._analyze_risks())
566564
results['recommendations'] = self._generate_recommendations(results)
567565
return results
568-
"removed_files": [],
569-
"modified_files": [],
570-
"added_functions": [],
571-
"removed_functions": [],
572-
"modified_functions": [],
573-
"complexity_increases": [],
574-
"complexity_decreases": [],
575-
"potential_issues": [],
576-
"recommendations": [],
577-
}
578-
579-
# Analyze file changes
580-
file_changes = self.analyze_file_changes()
581-
for file_path, change_type in file_changes.items():
582-
if change_type == "added":
583-
results["added_files"].append(file_path)
584-
elif change_type == "removed":
585-
results["removed_files"].append(file_path)
586-
elif change_type == "modified":
587-
results["modified_files"].append(file_path)
588-
589-
# Analyze function changes
590-
function_changes = self.analyze_function_changes()
591-
for function_name, change_type in function_changes.items():
592-
if change_type == "added":
593-
results["added_functions"].append(function_name)
594-
elif change_type == "removed":
595-
results["removed_functions"].append(function_name)
596-
elif change_type == "modified":
597-
results["modified_functions"].append(function_name)
598-
599-
# Analyze complexity changes
600-
complexity_changes = self.analyze_complexity_changes()
601-
for file_path, change in complexity_changes.items():
602-
if change > 0:
603-
results["complexity_increases"].append({
604-
"file": file_path,
605-
"increase": change,
606-
})
607-
elif change < 0:
608-
results["complexity_decreases"].append({
609-
"file": file_path,
610-
"decrease": abs(change),
611-
})
612566

613-
# Identify potential issues
567+
def _initialize_analysis_results(self):
568+
"""Initialize the analysis results dictionary with empty values."""
569+
return {
570+
"added_files": [],
571+
"removed_files": [],
572+
"modified_files": [],
573+
"added_functions": [],
574+
"removed_functions": [],
575+
"modified_functions": [],
576+
"complexity_increases": [],
577+
"complexity_decreases": [],
578+
"potential_issues": [],
579+
"recommendations": [],
580+
}
581+
582+
def _analyze_risks(self):
583+
"""Analyze potential risks in the changes."""
614584
risk_assessment = self.assess_risk()
615585
for category, risk_level in risk_assessment.items():
616586
if risk_level in ["high", "medium"]:
@@ -620,11 +590,6 @@ def perform_detailed_analysis(self) -> Dict[str, Any]:
620590
"description": self._get_risk_description(category, risk_level),
621591
})
622592

623-
# Generate recommendations
624-
results["recommendations"] = self._generate_recommendations(results)
625-
626-
return results
627-
628593
def _get_risk_description(self, category: str, risk_level: str) -> str:
629594
"""
630595
Get a description for a risk category and level.

codegen-on-oss/codegen_on_oss/analysis/swe_harness_agent.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,22 +203,22 @@ def _get_agent_analysis(
203203
}
204204

205205
try:
206-
from tenacity import retry, stop_after_attempt, wait_exponential
207-
208-
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
209-
def _make_agent_request(self, endpoint: str, payload: Dict[str, Any], timeout: int = 30) -> Dict[str, Any]:
210-
headers = {
211-
"Authorization": f"Bearer {self.agent_api_key}",
212-
"Content-Type": "application/json",
213-
}
214-
response = requests.post(
215-
f"{self.agent_api_url}/{endpoint}",
216-
headers=headers,
217-
json=payload,
218-
timeout=timeout
219-
)
220-
response.raise_for_status()
221-
return response.json()
206+
from tenacity import retry, stop_after_attempt, wait_exponential
207+
208+
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
209+
def _make_agent_request(self, endpoint: str, payload: Dict[str, Any], timeout: int = 30) -> Dict[str, Any]:
210+
headers = {
211+
"Authorization": f"Bearer {self.agent_api_key}",
212+
"Content-Type": "application/json",
213+
}
214+
response = requests.post(
215+
f"{self.agent_api_url}/{endpoint}",
216+
headers=headers,
217+
json=payload,
218+
timeout=timeout
219+
)
220+
response.raise_for_status()
221+
return response.json()
222222

223223
# Get the commit message
224224
commit_message = self._get_commit_message(repo_url, head_commit)

0 commit comments

Comments
 (0)