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

Use standard range checking - throw less exceptions #302

Open
scott-griffiths opened this issue Nov 27, 2023 · 0 comments
Open

Use standard range checking - throw less exceptions #302

scott-griffiths opened this issue Nov 27, 2023 · 0 comments

Comments

@scott-griffiths
Copy link
Owner

Currently a lot of methods will check bit ranges and throw exceptions for out of range positions.

Basically I'm thinking of anything that uses the _validate_slice method.

Standard slice checking doesn't do this - if an index is out of range it gets clipped to the extreme instead. By using this behaviour we can simplify some code and perhaps also be more Pythonic.

It's a breaking change, but not hugely so - some exceptions wouldn't be raised.

Validating a slice could then be done with just this:

i = slice(start, end, None).indices(len(self))
        return i[0], i[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant