Isort: Modules like _thread are considered FIRSTPARTY rather than STDLIB

Created on 12 Dec 2019  路  6Comments  路  Source: PyCQA/isort

The following file:

import sys
import _thread
import requests

gets sorted:

$ isort Test.py
Fixing Test.py

with the following results:

import sys

import requests

import _thread

It looks like built-in modules whose names start with _ (another example is _codecs) are not treated as STDLIB, but are treated like FIRSTPARTY instead, which seems wrong.

Discovered at https://github.com/PyCQA/pylint/issues/3304

I would suggest treating them like STDLIB where they belong, but then there's ambiguity. For now, when that is fixed, the sorting would put _thread in the beginning of the list, where it will be difficult to find. From my perspective, it would be appropriate to put it either to the end of the list, or before or after thread.

bug

All 6 comments

This should be fixed in develop and be pushed with the soon to be released 5.0.0 version.

Thanks!

~Timothy

@timothycrosley is this closed because it's been fixed, or will not be fixed?

Or by "should be fixed" did you mean "will be fixed", rather than "ought to be fixed"?

Strangely, I can work around this by using -b _thread with the CLI, but adding a builtin = ["_thread"] line in my pyproject.toml file doesn't work.

This is closed because it is fixed (albeit in develop branch):

In [1]: import isort                                                                                                                                                                                                                                                                                                                     
isor
In [2]: isort.place_module("_thread")                                                                                                                                                                                                                                                                                                    
Out[2]: 'STDLIB'

The 5.0.0 release that includes this is slated to be released July 4th - you can find out more here: https://timothycrosley.github.io/isort/docs/major_releases/introducing_isort_5/

Thank you! isort is such a great tool. Appreciate the work.

That means a lot to me! Glad you find isort useful!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

donjar picture donjar  路  3Comments

peteboothroyd picture peteboothroyd  路  3Comments

lee-kagiso picture lee-kagiso  路  4Comments

johnthagen picture johnthagen  路  3Comments

darkclouder picture darkclouder  路  3Comments