Skip to content

Commit

Permalink
Fixes for py3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
inno committed Apr 29, 2024
1 parent 1d35af6 commit 2b3c363
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions simplecli/simplecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,15 @@ def _set_description(self, line: str, force: bool = False) -> None:
return
self.description = re.sub(r"^#\s+", "", line.lstrip()).strip()

def parse_or_prepend(self, line: str, comment: str) -> bool:
def parse_or_prepend(
self,
line: str,
comment: str,
overwrite: bool = True,
) -> bool:
if not overwrite and self.description:
return False

line_set = self.parse_line(line)
if comment:
self._set_description(comment)
Expand Down Expand Up @@ -348,25 +356,24 @@ def extract_code_params(code: Callable[..., Any]) -> list[Param]:
param = None
params: list[Param] = []

while hints:
token = next(tokens)
depth = 0
for token in tokens:
depth += 1
if token.exact_type is COMMENT:
comment = token.string
if params and param is None:
params[-1].parse_or_prepend(token.line, comment)
comment = ""
elif param:
param.parse_or_prepend(token.line, comment, False)
continue
# tokenize.NL -
# when a logical line of code is continued over multiple lines
if token.exact_type is NL:
if not param:
continue
if token.exact_type is NL and param:
param.parse_or_prepend(token.line, comment)
elif token.exact_type is NAME:
if token.string not in hints:
continue
elif token.exact_type is NAME and token.string in hints:
hints.pop(token.string)
param = ordered_params[token.string]
param = ordered_params.pop(token.string)
if not param.parse_or_prepend(token.line, comment):
# Catch in the event a tokenize.NL is coming soon
continue
Expand All @@ -375,5 +382,6 @@ def extract_code_params(code: Callable[..., Any]) -> list[Param]:
comment = ""
params.append(param)
param = None

if param:
params.append(param)
return params

0 comments on commit 2b3c363

Please sign in to comment.