Skip to content

Commit

Permalink
Fixed linting issues and removed comments when provided comment is an…
Browse files Browse the repository at this point in the history
… empty string
  • Loading branch information
BrentBlanckaert committed Oct 25, 2024
1 parent f362c58 commit 88904a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions tested/dsl/ast_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,25 @@ def _translate_to_ast(node: ast.Interactive, is_return: bool) -> Statement:
else:
return _convert_statement(statement_or_expression)


def extract_comment(code: str) -> str:
"""
Extract the comment from the code.
:param code: The code to extract the comment from.
:return: The comment if it exists, otherwise an empty string.
"""
tokens = tokenize.tokenize(BytesIO(code.encode('utf-8')).readline)
comments = list(map(lambda t: t.string,
filter(lambda t: t.type == tokenize.COMMENT, tokens)))
tokens = tokenize.tokenize(BytesIO(code.encode("utf-8")).readline)
comments = list(
map(lambda t: t.string, filter(lambda t: t.type == tokenize.COMMENT, tokens))
)
if len(comments) == 0:
return ""
comment = comments[0][1:]
assert isinstance(comment, str)
return comment.strip()

Check warning on line 353 in tested/dsl/ast_translator.py

View check run for this annotation

Codecov / codecov/patch

tested/dsl/ast_translator.py#L351-L353

Added lines #L351 - L353 were not covered by tests


@overload
def parse_string(code: str, is_return: Literal[True]) -> Value: ...

Expand Down
3 changes: 2 additions & 1 deletion tested/languages/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def get_readable_input(
text = case.input.get_for(bundle.config.programming_language)
format_ = bundle.config.programming_language

text = f"{text} {bundle.language.comment(case.line_comment)}"
if case.line_comment:
text = f"{text} {bundle.language.comment(case.line_comment)}"

Check warning on line 155 in tested/languages/generation.py

View check run for this annotation

Codecov / codecov/patch

tested/languages/generation.py#L155

Added line #L155 was not covered by tests

# If there are no files, return now. This means we don't need to do ugly stuff.
if not case.link_files:
Expand Down

0 comments on commit 88904a8

Please sign in to comment.