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

next #3

Open
pmp-p opened this issue Dec 22, 2023 · 0 comments
Open

next #3

pmp-p opened this issue Dec 22, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@pmp-p
Copy link
Owner

pmp-p commented Dec 22, 2023

idea:

pkpy next should be called "iter_next" instead as its behaviour is radically different (does not raise) from CPython's next()

next(iterator[, default])
    
    Return the next item from the iterator. If default is given and the iterator
    is exhausted, it is returned instead of raising StopIteration.

that way it is easy to provide a similar function to other pythons
and keep codebases consistent.

to test

import builtins
builtins.iter_next = next
def next(it, default=0xdeadbeef):
    itrv = iter_next(it)
    if itrv == StopIteration:
        if default == 0xdeadbeef:
            raise itrv
        return default
    return itrv

builtins.next = next
@pmp-p pmp-p added the enhancement New feature or request label Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant