Skip to content

Commit

Permalink
Got rid of the tuple conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
BrentBlanckaert committed Nov 20, 2024
1 parent 165f94d commit c84cccc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tested/dsl/ast_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
"""

import ast
import collections
import io
import tokenize
from decimal import Decimal
from itertools import islice

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'islice' is not used.
from typing import Literal, cast, overload

from attrs import evolve
Expand Down Expand Up @@ -343,9 +345,10 @@ def extract_comment(code: str) -> str:
:return: The comment if it exists, otherwise an empty string.
"""
comment = ""
tokens = tuple(tokenize.generate_tokens(io.StringIO(code).readline))
if len(tokens) and tokens[-3].type == tokenize.COMMENT:
comment = tokens[-3].string.lstrip("#").strip()
tokens = tokenize.generate_tokens(io.StringIO(code).readline)
candidate = list(collections.deque(tokens, maxlen=3))
if len(candidate) and candidate[0].type == tokenize.COMMENT:
comment = candidate[0].string.lstrip("#").strip()
return comment


Expand Down

0 comments on commit c84cccc

Please sign in to comment.