Comments (2)
µsort is intentionally using case-insensitive (specifically casefolded) sorting for both module names and imported names. We believe that is a usability benefit, as it means "frog", "Frog", and "FROG" will all sort next to each other, without a user needing to think about which implicit "section" of an import statement they will find an element in. We also do not intend to offer options to change this behavior, as that complicates the implementation and makes it harder to test and reason about safety of the resulting changes.
See the "comparison to isort" and "non-goals" sections of the user guide for further explanation: https://usort.readthedocs.io/en/stable/why.html
from usort.
Some additional context on how we got to this state:
- We want "import a" and "import B" to sort naturally. There are some real-world examples like "Queue" from py2, case-insensitive filesystems, and another one that we've seen internally that benefit from this.
- We want "from x import a" and "from x import B" to sort naturally. We can't tell easily whether "a" and "B" are modules or names within a module without introspecting the source. We don't want to require the source to be available, thus this needs to be chosen based only on the strings "a" and "B" (actually "x.a" and "x.B").
- We want to use the same rule for non-from imports.
The only choice that's straightforward to document and doesn't require the source is "all names are sorted case-insensitively." I wasn't a fan at first, but John convinced me this was much simpler to explain than something special-casey like "from imports are case-sensitive but everything else isn't."
from usort.
Related Issues (20)
- Usort from STDIN HOT 2
- Consider using mypyc to speed things up like black does HOT 3
- Normalize leading blank lines when moving imports HOT 1
- Consider: sorting collection literals
- Add pre-commit hook HOT 2
- Support for Python 3.10's match operator HOT 2
- Examples comparing to isort's heuristics in the documentation seem outdated HOT 7
- KeyError while sorting duplicate imports HOT 1
- Treats external packages as internal HOT 5
- AssertionError when formatting semicolon-delimited import lines
- Test for backward compatibility against multiple other projects HOT 1
- Update release script for hatch instead of twine
- Unable to format 3.10 code with a `match` statement HOT 2
- Consider handling nested configuration
- usort incorrectly treats flatten_dict as a 1st party import HOT 1
- usort flatten multi-line imports despite magic-trailing-comma HOT 6
- usort drops inline comments in multi-line imports without trailing commas
- Request: `.pre-commit-hooks.yaml` HOT 1
- Support for notebooks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from usort.