Isort: `--diff` broken when reading from standard input

Created on 5 May 2020  路  2Comments  路  Source: PyCQA/isort

The latest (develop) version (tested at 394738e2a21737c23fdc67be399691341ca422fa) of isort appears to have regressed the handling of --diff when reading from standard input (originally fixed by #384 in the 4.x series).

--diff support with stdin is important to allow editor integrations to use isort on modified files and unsaved buffers as otherwise the editor would need to duplicate isort's locating of configuration files.

$ cat demo.py 
import os, sys, collections

$ isort --diff - < demo.py 
Traceback (most recent call last):
  File "/home/peter/.virtualenvs/isort/bin/isort", line 11, in <module>
    load_entry_point('isort', 'console_scripts', 'isort')()
  File "/home/play/isort/isort/main.py", line 600, in main
    **arguments,
  File "/home/play/isort/isort/api.py", line 104, in sorted_imports
    config = _config(path=file_path, config=config, **config_kwargs)
  File "/home/play/isort/isort/api.py", line 47, in _config
    config = Config(**config_kwargs)
  File "/home/play/isort/isort/settings.py", line 300, in __init__
    super().__init__(sources=tuple(sources), **combined_config)  # type: ignore
TypeError: __init__() got an unexpected keyword argument 'show_diff'

Perhaps surprisingly --diff works fine when given actual filenames:

$ isort --diff demo.py 
--- /tmp/isort-bug/demo.py:before   2020-05-05 22:00:57.723864
+++ /tmp/isort-bug/demo.py:after    2020-05-05 22:04:46.469076
@@ -1 +1,3 @@
-import os, sys, collections
+import os
+import sys
+import collections
Fixing /tmp/isort-bug/demo.py
bug

Most helpful comment

this is what VSCode uses by default and breaks the "sort imports" feature if you upgrade to isort >= 5

All 2 comments

this is what VSCode uses by default and breaks the "sort imports" feature if you upgrade to isort >= 5

This is fixed in the just released 5.1.1 version: https://github.com/timothycrosley/isort/releases/tag/5.1.1

Thanks for reporting!

~Timothy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cjerdonek picture cjerdonek  路  3Comments

and-semakin picture and-semakin  路  3Comments

whg517 picture whg517  路  3Comments

johnthagen picture johnthagen  路  3Comments

kevindaum picture kevindaum  路  4Comments