mahmoud / boltons

🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.
https://boltons.readthedocs.org
Other
6.51k stars 353 forks source link

Python 3 style iterable defaults #255

Open Indivicivet opened 4 years ago

Indivicivet commented 4 years ago

Is there any plan for an interface switch in boltons for a function "X" e.g. iterutils.pairwise() to return an iterable (as currently "X_iter" e.g. iterutils.pairwise_iter() does)? I think this would be more consistent with standard python 3 behaviour.

Similarly current frange() and xfrange() are python 2-style matching range and xrange, but this seems weird when xrange doesn't exist in python 3. Tangentially, range is a bit fancier than just being an iterator, such as with 5 in range(1, 99999999999, 2) working without eating all of your memory, and it would be ideal if an frange also had this behaviour.

An instance of this outside of iterutils is with .items() and .iteritems() in dictutils.OrderedMultiDict -- it could possibly be good for .items() to behave the same as the built in dict.items().

mahmoud commented 4 years ago

Hi @Indivicivet, that's a thoughtful point. Probably if boltons started today it'd do things in line with the emerging conventions.

But as for the mature boltons we have today, no, no such plan at the moment. For instance, for the OMD, it probably wouldn't be too hard to have branched definitions, depending on which version of Python is importing, similar to how funcutils already has to work. But it's not something I'm rushing to do because then the tests need branches, too, and the docs as well. funcutils again demonstrating the heavy toll. But I guess if it was done right, I'd consider a PR.

I'm not saying never, but I would want to have a decent discussion about, because I'm fairly sure even many Python core devs would try to avoid breaking backwards compat again if they could choose. :)

mblahay commented 4 years ago

@mahmoud, Do you have any metrics on how many python2 installations versus python3 installations are using boltons?

mblahay commented 3 years ago

I found the download metrics for the last 30 days. The vast majority are python 3.6 and above.

3.6 | 464325 |   3.7 | 245761 |   3.8 | 64091 |   2.7 | 41436 |   3.5 | 12107 |   3.9 | 2442 |   3.4 | 124 |   3.10 | 65