separate_packages splits imports from the same explicitly configured package
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
Direzione di ricerca
Il bug è in _separate_packages() in isort/output.py, dove package_depth viene calcolato contando i punti nella stringa del motivo di corrispondenza, includendo erroneamente il punto di re.compile. Inizia riproducendo i due esempi pycon della issue con isort.code e separate_packages impostato su THIRDPARTY. È completato quando from pkg import a e from pkg.sub import b finiscono nello stesso gruppo e l'esempio dj non configurato si comporta ancora allo stesso modo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
The separate_packages option inserts spurious blank lines between imports
that belong to the same package, whenever that package is explicitly listed
in a known_* configuration option. The grouping only works by accident for
packages that were not explicitly configured.
Steps to reproduce
With isort 9.0.2:
>>> import isort
>>> print(isort.code(
... "from pkg import a\nfrom pkg.sub import b\n",
... separate_packages=["THIRDPARTY"],
... known_third_party=["pkg"],
... ))
from pkg import a
from pkg.sub import b
and with straight imports:
>>> print(isort.code(
... "import pkg.a\nimport pkg.b\n",
... separate_packages=["THIRDPARTY"],
... known_third_party=["pkg"],
... ))
import pkg.a
import pkg.b
For comparison, the same shapes with an unconfigured package are grouped
correctly on one package:
>>> print(isort.code(
... "from dj import a\nfrom dj.sub import b\nimport dj.x\nimport dj.y\n",
... separate_packages=["THIRDPARTY"],
... known_third_party=["dj2"],
... ))
import dj.x
import dj.y
from dj import a
from dj.sub import b
Actual behavior
from pkg import a and from pkg.sub import b (same package pkg) are split
into two groups; likewise import pkg.a / import pkg.b.
Expected behavior
Imports from the same package form one group:
from pkg import a
from pkg.sub import b
This also matters for the original use case of grouping by package within a
configured section, e.g. known_firstparty=["src"]: every module under src
currently gets its own "package" group (src.pkg, src.other, ...) instead
of being grouped under src.
Suspected cause
_separate_packages() in isort/output.py derives the package-key depth
for matched known patterns by counting dots in the reason string:
package_depth = len(reason.split(".")) - 1 # minus 1 for re.compile
The reason for a known match is
Matched configured known pattern re.compile('^pkg$'). Splitting that on
. yields two parts, so package_depth becomes 1 even though the matched
pattern ^pkg$ contains a single segment. The dot used to subtract
re.compile is counted as a pattern segment, which inflates the depth by one
for every configured pattern: the key for pkg.a/pkg.b becomes
pkg.a/pkg.b instead of pkg. Multi-segment patterns (pkg.sub) are
inflated the same way, so the grouping breaks for any explicitly configured
package.
- Lingua principale
- Python
- Stelle
- 7k
- Fork
- 838
- Merge medio
- 2g 6h
- PR unite (30g)
- 19
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PyCQA/isort
-
force_sort_within_sections does not sort lazy imports by module nameForse già presa @rahul05ranjan l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 2 giorni
-
length_sort with native sort order puts a longer import firstForse già presa @simpleqt l’ha presa 24 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
PyCQA/isort#2698 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Cache compiled known-module patterns across Config instancesForse già presa @Yin123-ybh l’ha presa 2 giorni fa. Aperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 30/100
PyCQA/isort#2805 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
add_imports re-adds the import on every run when the file contains an `# isort: off` block (not idempotent)Forse già presa @Tanvi-007 l’ha presa 6 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
PyCQA/isort#2799 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
multi_line_output=1 with include_trailing_comma leaves a dangling comma on a single importForse già presa @beduldul l’ha presa 29 giorni fa. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 15/100
PyCQA/isort#2752 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
TigreGotico/text2spoken#626 ·
I maintainer di solito rispondono entro 1 giorno
-
oncoref MappingProxyType in proteome.layers breaks deepcopy in reference_coverage._inventoryForse già presa @iskandr l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
pipecat-ai/pipecat#7014 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
NL-BioImaging/biomero#136 ·
I maintainer di solito rispondono entro 1 giorno
-
Installing from source leaves out all subpackages (fastai.vision, fastai.text, ...)Forse già presa @lejrn l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100