Skip to content

Commit fb5529e

Browse files
authored
Add optional values for CodeTFv3 types (#1054)
* Add optional values for CodeTFv3 types * ChangeSets can also be optional when finding is not fixed * Move FixQuality and Rating to common codetf module
1 parent 40bb897 commit fb5529e

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

src/codemodder/codetf/common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,14 @@ def validate_description(self):
8484
if self.description is not None and not self.description:
8585
raise ValueError("description must not be empty")
8686
return self
87+
88+
89+
class Rating(BaseModel):
90+
score: int
91+
description: Optional[str] = None
92+
93+
94+
class FixQuality(BaseModel):
95+
safetyRating: Rating
96+
effectivenessRating: Rating
97+
cleanlinessRating: Rating

src/codemodder/codetf/v2/codetf.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from ..common import Change as CommonChange
2222
from ..common import (
2323
CodeTFWriter,
24+
FixQuality,
2425
Rule,
2526
)
2627

@@ -104,17 +105,6 @@ class Strategy(Enum):
104105
deterministic = "deterministic"
105106

106107

107-
class Rating(BaseModel):
108-
score: int
109-
description: Optional[str] = None
110-
111-
112-
class FixQuality(BaseModel):
113-
safetyRating: Rating
114-
effectivenessRating: Rating
115-
cleanlinessRating: Rating
116-
117-
118108
class ChangeSet(BaseModel):
119109
"""A set of changes made to a file at `path`"""
120110

src/codemodder/codetf/v3/codetf.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from pydantic import BaseModel, model_validator
77

8-
from ..common import Change, CodeTFWriter, Finding
8+
from ..common import Change, CodeTFWriter, Finding, FixQuality
99
from ..v2.codetf import Finding as V2Finding
1010

1111

@@ -41,14 +41,14 @@ class FixStatus(BaseModel):
4141
"""Metadata describing fix outcome"""
4242

4343
status: FixStatusType
44-
reason: Optional[str]
45-
details: Optional[str]
44+
reason: Optional[str] = None
45+
details: Optional[str] = None
4646

4747

4848
class ChangeSet(BaseModel):
4949
path: str
5050
diff: str
51-
changes: list[Change]
51+
changes: list[Change] = []
5252

5353

5454
class Reference(BaseModel):
@@ -88,27 +88,16 @@ class FixMetadata(BaseModel):
8888
summary: str
8989
# A detailed description of the fix
9090
description: str
91-
references: list[Reference]
91+
references: list[Reference] = []
9292
generation: GenerationMetadata
9393

9494

95-
class Rating(BaseModel):
96-
score: int
97-
description: Optional[str] = None
98-
99-
100-
class FixQuality(BaseModel):
101-
safetyRating: Rating
102-
effectivenessRating: Rating
103-
cleanlinessRating: Rating
104-
105-
10695
class FixResult(BaseModel):
10796
"""Result corresponding to a single finding"""
10897

10998
finding: Finding | V2Finding
11099
fixStatus: FixStatus
111-
changeSets: list[ChangeSet]
100+
changeSets: list[ChangeSet] = []
112101
fixMetadata: Optional[FixMetadata] = None
113102
fixQuality: Optional[FixQuality] = None
114103
# A description of the reasoning process that led to the fix

0 commit comments

Comments
 (0)