Skip to content

Commit

Permalink
Fix type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
boehmseb committed Mar 18, 2024
1 parent d6f2e36 commit 2958347
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions varats/varats/tools/driver_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __prompt_location(
feature_name: str,
commit_hash: FullCommitHash,
old_location: tp.Optional[Location] = None
) -> tp.Optional[Location]:
) -> Location:
parse_location: tp.Callable[[str], tp.Optional[Location]]
if old_location is not None:
parse_location = partial(
Expand All @@ -116,22 +116,26 @@ def __prompt_location(
else:
parse_location = Location.parse_string

return click.prompt(
f"Enter location for feature {feature_name} @ {commit_hash.short_hash}",
value_proc=parse_location
return tp.cast(
Location,
click.prompt(
f"Enter location for feature {feature_name} @ {commit_hash.short_hash}",

Check failure on line 122 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/tools/driver_feature.py#L122 <301>

Line too long (84/80) (line-too-long)
Raw output
varats/varats/tools/driver_feature.py:122:0: C0301: Line too long (84/80) (line-too-long)
value_proc=parse_location
)
)


def __get_location_content(commit: Commit,
location: Location) -> tp.Optional[str]:
assert location.start_line == location.end_line, \
"Multiline locations are not supported yet."
lines = tp.cast(Blob, commit.tree[location.file]).data.splitlines()
lines: tp.List[bytes] = tp.cast(Blob, commit.tree[location.file
]).data.splitlines()

if len(lines) < location.start_line:
return None

line = lines[location.start_line - 1].decode("utf-8")
line: str = lines[location.start_line - 1].decode("utf-8")

if len(line) <= location.end_col:
return None
Expand All @@ -157,7 +161,7 @@ def main() -> None:
required=False
)
def __annotate(
project: str, revision: tp.Optional[str], outfile: tp.IO
project: str, revision: tp.Optional[str], outfile: tp.TextIO
) -> None:
initialize_cli_tool()

Expand Down Expand Up @@ -187,9 +191,9 @@ def __annotate(
last_annotations[feature_name] = FeatureAnnotation(
feature_name, location, commit_hash
)
last_annotation_targets[feature_name] = __get_location_content(
first_commit, location
)
target = __get_location_content(first_commit, location)
assert target is not None, "Target must not be None"
last_annotation_targets[feature_name] = target
tracked_features[feature_name] = []
LOG.debug(
f"Tracking {feature_name} @ {location}: {last_annotation_targets[feature_name]}"

Check failure on line 199 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/tools/driver_feature.py#L199 <301>

Line too long (92/80) (line-too-long)
Raw output
varats/varats/tools/driver_feature.py:199:0: C0301: Line too long (92/80) (line-too-long)
Expand Down Expand Up @@ -221,9 +225,9 @@ def __annotate(
last_annotations[feature] = FeatureAnnotation(
feature, new_location, commit_hash
)
last_annotation_targets[feature] = __get_location_content(
commit, new_location
)
new_target = __get_location_content(commit, new_location)
assert new_target is not None, "Target must not be None"
last_annotation_targets[feature] = new_target
LOG.debug(
f"Tracking {feature} @ {new_location}: {last_annotation_targets[feature]}"

Check failure on line 232 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/tools/driver_feature.py#L232 <301>

Line too long (94/80) (line-too-long)
Raw output
varats/varats/tools/driver_feature.py:232:0: C0301: Line too long (94/80) (line-too-long)
)
Expand Down

0 comments on commit 2958347

Please sign in to comment.