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

Shorter, possibly more efficient code #41

Merged
merged 5 commits into from
Oct 18, 2021
Merged

Shorter, possibly more efficient code #41

merged 5 commits into from
Oct 18, 2021

Conversation

adbar
Copy link
Contributor

@adbar adbar commented Oct 15, 2021

  • Unnecessary lines removed
  • Possibly faster code through pre-compiled regex and list comprehension

Copy link
Owner

@miso-belica miso-belica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I added some notes. Please take a look :)

justext/paragraph.py Outdated Show resolved Hide resolved
justext/utils.py Outdated
Comment on lines 26 to 28
if "\n" in text or "\r" in text:
return "\n"
else:
return " "
return " "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this may be seen as unnecessary, but I like to see it visually clear these are 2 distinctive branches rather than some filtering by early return followed by an algorithm. Maybe a single line would be better.

Suggested change
if "\n" in text or "\r" in text:
return "\n"
else:
return " "
return " "
return "\n" if "\n" in text or "\r" in text else " "

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done ✔️

@miso-belica miso-belica self-assigned this Oct 17, 2021
Copy link
Owner

@miso-belica miso-belica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

@miso-belica miso-belica merged commit a9a1155 into miso-belica:main Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants