HypothesisWorks / hypothesis

Hypothesis is a powerful, flexible, and easy to use library for property-based testing.
https://hypothesis.works
Other
7.43k stars 578 forks source link

isort has a confused idea of alphabetical order #567

Closed alexwlchan closed 7 years ago

alexwlchan commented 7 years ago

Two examples:

  1. https://travis-ci.org/HypothesisWorks/hypothesis-python/jobs/224768835

    What definition of alphabetical sorts from hypothesis import given, example instead of example, given?

  2. https://github.com/HypothesisWorks/hypothesis-python/blob/master/src/hypothesis/internal/reflection.py#L24

    import re
    import ast
    import types
    import hashlib
    import inspect

    Wut.

DRMacIver commented 7 years ago

No, that's our configuration: The sort order is shortest first then ties broken alphabetically.

It's probably worth changing that given the number of people it has confused. I don't really have any strong opinion in favour of it staying that way, it's just what I happened to pick early in the project and it's stayed that way by inertia.

That being said, I think I have spotted some cases where it's confused about sort order in our code recently.

DRMacIver commented 7 years ago

I guess one slightly tongue in cheek argument for this is that Hypothesis is designed for the combinatorial optimization problem of producing shortlex (that order) minimal examples, so it's thematically appropriate. 😉

But I genuinely don't really care and would happily accept a patch to change the order to a more normal one.

alexwlchan commented 7 years ago

The sort order is shortest first then ties broken alphabetically.

That’s a bizarre convention, but it explains so much.

Multiple times I’ve tried to get the imports right by eye, only for isort to suggest what seems like an utterly random ordering.

DRMacIver commented 7 years ago

That’s a bizarre convention

I find it kinda aesthetically pleasing because it groups similar complexity things together (it's really for across line sorting that I care about it, not within lines), but I admit it's an unusual life choice.

but it explains so much.

Sorry, I thought you knew that, or I'd have explained properly before. The confusing thing for me with isort recently was some of the ways in which it changed, not the fundamental sort order

DRMacIver commented 7 years ago

I'm going too close this as WAI, but feel free to propose a change if it still bugs you.