Skip to content

Commit bb95515

Browse files
committed
Added method to create ResultSets from the same type
1 parent 63e302a commit bb95515

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/codemodder/codemods/base_codemod.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ def _apply_remediation(
212212
if results:
213213
for result in results.results_for_rules(rules):
214214
# this need to be the same type of ResultSet as results
215-
singleton = results.__class__()
216-
singleton.add_result(result)
215+
singleton = results.from_single_result(result)
217216
result_locations = self.get_files_to_analyze(context, singleton)
218217
# We do an execution for each location in the result
219218
# So we duplicate the resultset argument for each location

src/codemodder/result.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ def files_for_rule(self, rule_id: str) -> list[Path]:
284284
def all_rule_ids(self) -> list[str]:
285285
return list(self.keys())
286286

287+
@classmethod
288+
def from_single_result(cls, result: ResultType) -> Self:
289+
"""
290+
Creates a new ResultSet of the same type with a give result.
291+
"""
292+
new = cls()
293+
new.add_result(result)
294+
return new
295+
287296
def __or__(self, other):
288297
result = self.__class__()
289298
for k in self.keys() | other.keys():

0 commit comments

Comments
 (0)