Skip to content

Add step to zen command slicing #3311

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

Merged
merged 4 commits into from
Apr 14, 2025
Merged

Add step to zen command slicing #3311

merged 4 commits into from
Apr 14, 2025

Conversation

MeGaGiGaGon
Copy link
Contributor

@MeGaGiGaGon MeGaGiGaGon commented Apr 11, 2025

This adds the long awaited ability to step while slicing to the !zen command, so you can finally do stupid things like getting every other line in reverse.

The regex was completely reworked to allow for the steps (I finally got to use ++ for something) (groups are now named instead of indexed for clarity)

Line numbers for display are now found via zen_lines.index instead of math. I am aware this is worse for performance, but it is a massive win for both ease of implementation and code clarity, since with negative steps the clamping and offset math for line numbers gets very hard very quick. The main downside of this approach is the math can offer very fine-grained error messaging, whereas the current code gives a generic "Slice returned 0 lines." message.

Due to how the change is implemented, more slicings are now valid than before, ie !zen :100 will now work, so those test case fails were removed.

I am aware this will probably fail the formatting and linting CI passes, but I could not run them locally as my computer's OS is on it's deathbed and poetry refuses to work correctly.

Edit:
All things now fixed. The tests for full zen (0:19, :, ::) were failing because the source/default description included an extra \n, so I added a .strip() to fix that.
One other thing I forgot to say above, with the easier implementation from indexing I was able to clean up the messages that bugged me, so now if only one line is returned after slicing it will always say (line x) instead of (lines x-x), and if the slice returns the full thing, it will be , by Tim Peters instead of (lines 0-18)

Copy link
Member

@vivekashok1221 vivekashok1221 left a comment

Choose a reason for hiding this comment

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

LGTM

@jb3 jb3 merged commit 2d4f688 into python-discord:main Apr 14, 2025
5 checks passed
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.

3 participants