Skip to content

Conversation

asottile
Copy link
Member

flatten is an alias in more-itertools anyway

flatten is an alias in more-itertools anyway
@asottile
Copy link
Member Author

We only use more-itertools in 3 places, this place provided zero benefit as far as I can tell. given the pain in #4770 and our extremely sparse usage of this library maybe we should factor it out?

@nicoddemus
Copy link
Member

Not sure... the alternative to dropping more-itertools would be for us to implement that ourselves, which I'm not a big fan of.

And to be fair, #4770 is not more-itertools' fault, but setuptools', and is being solved already by #4774. I would say we can consider removing it in the future if it causes us pain again in the future, but I would like to give it another chance if possible.

What do others think?

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Thanks!

@asottile
Copy link
Member Author

Not sure... the alternative to dropping more-itertools would be for us to implement that ourselves, which I'm not a big fan of.

And to be fair, #4770 is not more-itertools' fault, but setuptools', and is being solved already by #4774. I would say we can consider removing it in the future if it causes us pain again in the future, but I would like to give it another chance if possible.

What do others think?

We currently use 2 functions which I think are trivially implemented (not sure how m-i implements them, but here's my best attempt)

def always_iterable(x):
    if isinstance(x, (six.text_type, bytes)):
        return (x,)
    else:
        try:
            return tuple(x)
         except TypeError:
            return (x,)


def collapse(val, tps=(type, six.text_type, bytes)):
    def inner(x):
        if isinstance(x, tps):
            yield x
        else:
             try:
                 it = iter(x)
             except TypeError:
                 yield x
             else:
                 for y in it:
                     for z in inner(y):
                         yield z
    return tuple(inner(val))

@asottile asottile merged commit f0e6bf7 into pytest-dev:master Feb 13, 2019
@asottile asottile deleted the stdlib branch February 13, 2019 02:37
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.

2 participants