Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 4550c46

Browse files
feat: Add reviewResult in AbstactAnnotation class (#1122)
Closes #1121 . ### Summary of Changes added field reviewResult in AbstractAnnotation and changes all relevated json files, dicts, and instantiation ### Testing Instructions view and run the changed `test_annotations.py` file or import and export api data with the existing commands (api, migrate, etc.). Co-authored-by: Aclrian <[email protected]> Co-authored-by: Lars Reimann <[email protected]>
1 parent a48a235 commit 4550c46

File tree

11 files changed

+549
-384
lines changed

11 files changed

+549
-384
lines changed

package-parser/package_parser/processing/annotations/_generate_boundary_annotations.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from package_parser.processing.annotations.model import (
44
AnnotationStore,
55
BoundaryAnnotation,
6+
EnumReviewResult,
67
Interval,
78
ValueAnnotation,
89
)
@@ -17,6 +18,7 @@ def _generate_boundary_annotations(api: API, annotations: AnnotationStore) -> No
1718
:param api: Description of the API
1819
:param annotations: AnnotationStore, that holds all annotations
1920
"""
21+
# pylint: disable=duplicate-code
2022
for _, parameter in api.parameters().items():
2123

2224
# Don't add boundary annotation to constant parameters
@@ -73,5 +75,6 @@ def _generate_boundary_annotations(api: API, annotations: AnnotationStore) -> No
7375
reviewers=[],
7476
comment=f"I turned this into a bounded number because the description contained {boundary_type.full_match}.",
7577
interval=interval,
78+
reviewResult=EnumReviewResult.NONE,
7679
)
7780
annotations.boundaryAnnotations.append(boundary)

package-parser/package_parser/processing/annotations/_generate_enum_annotations.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
AnnotationStore,
55
EnumAnnotation,
66
EnumPair,
7+
EnumReviewResult,
78
ValueAnnotation,
89
)
910
from package_parser.processing.api.model import API, EnumType
@@ -17,6 +18,7 @@ def _generate_enum_annotations(api: API, annotations: AnnotationStore) -> None:
1718
:param api: API object for usages
1819
:param annotations: AnnotationStore object
1920
"""
21+
# pylint: disable=duplicate-code
2022
for _, parameter in api.parameters().items():
2123

2224
# Don't add enum annotation to constant parameters
@@ -47,6 +49,7 @@ def _generate_enum_annotations(api: API, annotations: AnnotationStore) -> None:
4749
comment=f"I turned this into an enum because the type in the documentation contained {full_match}.",
4850
enumName=enum_name,
4951
pairs=pairs,
52+
reviewResult=EnumReviewResult.NONE,
5053
)
5154
)
5255

package-parser/package_parser/processing/annotations/_generate_remove_annotations.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from package_parser.processing.annotations.model import (
22
AnnotationStore,
3+
EnumReviewResult,
34
RemoveAnnotation,
45
)
56
from package_parser.processing.api.model import API
@@ -26,6 +27,7 @@ def _generate_remove_annotations(
2627
authors=[autogen_author],
2728
reviewers=[],
2829
comment=_create_explanation("class", n_class_usages),
30+
reviewResult=EnumReviewResult.NONE,
2931
)
3032
)
3133

@@ -38,6 +40,7 @@ def _generate_remove_annotations(
3840
authors=[autogen_author],
3941
reviewers=[],
4042
comment=_create_explanation("function", n_function_usages),
43+
reviewResult=EnumReviewResult.NONE,
4144
)
4245
)
4346

package-parser/package_parser/processing/annotations/_generate_value_annotations.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from package_parser.processing.annotations.model import (
44
AnnotationStore,
55
ConstantAnnotation,
6+
EnumReviewResult,
67
OmittedAnnotation,
78
OptionalAnnotation,
89
RequiredAnnotation,
@@ -22,9 +23,9 @@ def _generate_value_annotations(
2223
for parameter in api.parameters().values():
2324

2425
# Don't create annotations for variadic parameters
25-
if (
26-
parameter.assigned_by == ParameterAssignment.POSITIONAL_VARARG
27-
or parameter.assigned_by == ParameterAssignment.NAMED_VARARG
26+
if parameter.assigned_by in (
27+
ParameterAssignment.POSITIONAL_VARARG,
28+
ParameterAssignment.NAMED_VARARG,
2829
):
2930
continue
3031

@@ -54,6 +55,7 @@ def _generate_constant_annotation(
5455
authors=[autogen_author],
5556
reviewers=[],
5657
comment=f"I omitted this parameter because it is always set to the original default value ({parameter.default_value}).",
58+
reviewResult=EnumReviewResult.NONE,
5759
)
5860
)
5961
return
@@ -68,6 +70,7 @@ def _generate_constant_annotation(
6870
authors=[autogen_author],
6971
reviewers=[],
7072
comment=f"I replaced this parameter with a constant because it is always set to the same literal value ({sole_stringified_value}).",
73+
reviewResult=EnumReviewResult.NONE,
7174
defaultValueType=default_value_type,
7275
defaultValue=default_value,
7376
)
@@ -79,6 +82,7 @@ def _generate_constant_annotation(
7982
authors=[autogen_author],
8083
reviewers=[],
8184
comment=f"I made this parameter required because, even though it is always set to the same value ({sole_stringified_value}), that value is not a literal.",
85+
reviewResult=EnumReviewResult.NONE,
8286
)
8387
)
8488

@@ -98,6 +102,7 @@ def _generate_required_or_optional_annotation(
98102
authors=[autogen_author],
99103
reviewers=[],
100104
comment=f"I made this parameter required because the most common value ({most_common_values[0]}) is not a literal.",
105+
reviewResult=EnumReviewResult.NONE,
101106
)
102107
)
103108
return
@@ -122,6 +127,7 @@ def _generate_required_or_optional_annotation(
122127
authors=[autogen_author],
123128
reviewers=[],
124129
comment=comment,
130+
reviewResult=EnumReviewResult.NONE,
125131
)
126132
)
127133
else:
@@ -136,6 +142,7 @@ def _generate_required_or_optional_annotation(
136142
authors=[autogen_author],
137143
reviewers=[],
138144
comment=comment,
145+
reviewResult=EnumReviewResult.NONE,
139146
defaultValueType=default_value_type,
140147
defaultValue=default_value,
141148
)
@@ -186,11 +193,10 @@ def _should_be_required(
186193
False,
187194
f"I made this parameter optional because there is a statistically significant most common value (p-value {p_value:.2%} <= significance level {significance_level:.0%}).",
188195
)
189-
else:
190-
return (
191-
True,
192-
f"I made this parameter required because there is no statistically significant most common value (p-value ({p_value:.2%}) > significance level ({significance_level:.0%}).",
193-
)
196+
return (
197+
True,
198+
f"I made this parameter required because there is no statistically significant most common value (p-value ({p_value:.2%}) > significance level ({significance_level:.0%}).",
199+
)
194200

195201

196202
def _is_stringified_literal(stringified_value: str) -> bool:
@@ -203,14 +209,13 @@ def _get_type_and_value_for_stringified_value(
203209
) -> tuple[Optional[ValueAnnotation.DefaultValueType], Any]:
204210
if stringified_value == "None":
205211
return ValueAnnotation.DefaultValueType.NONE, None
206-
elif stringified_value == "True" or stringified_value == "False":
212+
if stringified_value in ("True", "False"):
207213
return ValueAnnotation.DefaultValueType.BOOLEAN, stringified_value == "True"
208-
elif _is_float(stringified_value):
214+
if _is_float(stringified_value):
209215
return ValueAnnotation.DefaultValueType.NUMBER, float(stringified_value)
210-
elif stringified_value[0] == "'" and stringified_value[-1] == "'":
216+
if stringified_value[0] == "'" and stringified_value[-1] == "'":
211217
return ValueAnnotation.DefaultValueType.STRING, stringified_value[1:-1]
212-
else:
213-
return None, None
218+
return None, None
214219

215220

216221
def _is_float(stringified_value: str) -> bool:

package-parser/package_parser/processing/annotations/model/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
DescriptionAnnotation,
99
EnumAnnotation,
1010
EnumPair,
11+
EnumReviewResult,
1112
ExpertAnnotation,
1213
GroupAnnotation,
1314
Interval,

0 commit comments

Comments
 (0)