-
-
Notifications
You must be signed in to change notification settings - Fork 145
Standardize string formatting to use f-strings #278
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
Conversation
kernc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, pdoc/html_helpers.py and pdoc/templates/{html,pdf}.mako contain some further str.format() / str.__mod__ calls.
You are right, will be checking on the missed files |
|
Re-checked all documents to pick up on missed
Edited:
|
|
Two questions: pdoc/html_helpers.py (line 176)
Lines 176 to 177 in 414739b
Reformatting it would give return '\n\n'.join(f'`{line.split(":", 1)[0].strip()}`\n: '
f'{line.split(":", 1)[1].strip()}' for line in filter(None, spec_with_desc.split('\n')))but it looks rather inelegant. Are we good with this? pdoc/templates/pdf.mako (line 18)Lines 17 to 20 in 414739b
One of the inputs to def paragraph_fmt(m):
sub = re.sub('\n {,4}', '\n', m.group(4))
return f'{m.group(2)}**{m.group(3)}:** {sub}'
text = re.sub(r'^(?P<indent>( *))!!! \w+ \"([^\"]*)\"(.*(?:\n(?P=indent) +.*)*)',
paragraph_fmt, text, flags=re.MULTILINE)Would love to have your comments @kernc |
|
Snippets like these show I don't mind new variables in both cases. In the first case maybe: spec, desc = map(...)
return f"..."When in doubt, opt for clarity. |
Thanks for the thoughts, at some point I was contemplating if it's better to leave them as-is actually. Anywho, I've finished updating each file in their own commit, whole PR is ready for review. |
Reworded variable name to be more meaningful Co-authored-by: kernc <kerncece@gmail.com>
|
Many thanks @tnwei! Hope you got your t(r)ee. 😄 |
* MNT: Bumped Python version reqs to 3.6+ * ENH: Updated string formatting to use f-strings * ENH: Resolved individual code comments in pdoc3#278 * ENH: __init__.py refactored to use f-strings * ENH: cli.py refactored to use f-strings * ENH: pdoc/test/__init__.py refactored to use f-strings * ENH: pdoc/templates/html.mako refactored to use f-strings * ENH: pdoc/html_helpers.py refactored to use f-strings * ENH: pdoc/templates/pdf.mako refactored to use f-strings * Update pdoc/html_helpers.py Reworded variable name to be more meaningful
As per #270 , submitting this pull request to revamp string formatting in
pdocto use f-strings. Also bumped min requirements of Python 3.5+ to Python 3.6+ insetup.py.Following
CONTRIBUTING.md:python setup.py testflake8 --max-line-length 100, no new warnings. At time of writing, existing warning is: