Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip hash and space in comments, not just first symbol #218

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nb2workflow/nbadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def _pop_comment_by_line(comment_tokens, l):
for i, x in enumerate(comment_tokens):
if x.start[0]==l:
res = comment_tokens.pop(i)
return res.string[1:]
return res.string.strip(' #')
return ''

def parse_source_multiline(self, source: str) -> dict[str, list[dict]]:
Expand Down Expand Up @@ -469,7 +469,7 @@ def parse_source_multiline(self, source: str) -> dict[str, list[dict]]:

# now parse full-line comments
for comment in comments:
cstring = comment.string[1:]
cstring = comment.string.strip('# ')
result['standalone'].append(cstring)

return result
Expand Down
4 changes: 2 additions & 2 deletions tests/testfiles/multiline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"\n",
"opt: float|None = None\n",
"otheropt = 5 # oda:optional\n",
"intfloat = 10 # oda:Float\n",
"intfloat = 10 # # oda:Float\n",
"inten: int = 45 # oda:Energy \n",
"# NOTE: won't work with dispatcher, because energy is always float there\n",
"string_param = '''Foo Bar\n",
Expand Down Expand Up @@ -62,7 +62,7 @@
},
"language_info": {
"name": "python",
"version": "3.10.12"
"version": "3.10.15"
}
},
"nbformat": 4,
Expand Down