GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — py: normalize bounds for string find and count by ac1982 · Pull Request #263 · go-python/gpython

Conversation

@ac1982

@ac1982 ac1982 commented Oct 12, 2026

Copy link
Copy Markdown

'abcabc'.find('a', -3) and .count('a', -3) panic on negative Go slice bounds. Negative end indices are treated as the string's full length, and empty substring searches can match even when start is past the end or the requested interval is reversed.

Share boundary normalization between find and count: translate negative indices relative to the Unicode character length, clamp overly negative bounds and overly large ends, and return no match for reversed or out-of-range starts. The actual search/count algorithms remain unchanged.

Adds 28 direct cases with expectations independently obtained from CPython, plus six Python interpreter assertions covering ASCII, Unicode, empty strings and empty patterns. Eighteen direct cases fail before the fix, including panics.

Validation: full go test -tags=ci -race ./... on Go 1.27.1 and full GOTOOLCHAIN=go1.19.13 go test -tags=ci ./... pass on Linux/arm64. goimports/diff checks pass. Standalone vet and Staticcheck 2026.2.1 diagnostics are byte-identical to clean upstream 444ae5e (existing unkeyed literals, unreachable code and an unused assignment). Historical Staticcheck and other OS/architecture jobs were not run.

Contributor registration: go-python/license#24. AI-assisted implementation and validation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ac1982
py: normalize bounds for string find and count
b122a93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@ac1982
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.