Skip to content

Documentation of strictly_n parameters too_short and too_long is misleading #1054

@Dutcho

Description

@Dutcho

The documentation states:

more_itertools.strictly_n(iterable, n, too_short=None, too_long=None)
Validate that iterable has exactly n items and return them if it does.
If it has fewer than n items, call function too_short with those items. If it has more than n items, call function too_long with the first n + 1 items.

However, as the [source] shows:

    if sent < n:
        too_short(sent)
        return

    for item in it:
        too_long(n + 1)
        return

the documentation should read:

...
If it has fewer than n items, call function too_short with the item-count of those items. If it has more than n items, call function too_long with the number n + 1.

The provided examples also demonstrate that the functions receive counts, not items.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions