isort --src-path crashes with TypeError: __init__() got an unexpected keyword argument 'source_paths'

Created on 26 Jun 2020  路  2Comments  路  Source: PyCQA/isort

With develop (e3f5300b8be2f293957f0573247f14dce6139aa0):

$ isort --src-path=. .
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/anders/python/isort/isort/main.py", line 647, in main
    config = Config(**config_dict)
  File "/home/anders/python/isort/isort/settings.py", line 329, in __init__
    super().__init__(sources=tuple(sources), **combined_config)  # type: ignore
TypeError: __init__() got an unexpected keyword argument 'source_paths'
bug

Most helpful comment

Your commit has a bug that accidentally gives me exactly the behavior I want and fixes the huge performance regression (#1239), so I will happily use it鈥攂ut I feel honor-bound to point out that these mutations to src_paths now have no effect on config_dict:

-    src_paths = config_dict.setdefault("src_paths", set())
+    src_paths = set(config_dict.setdefault("src_paths", ()))
     for file_name in file_names:
         if os.path.isdir(file_name):
             src_paths.add(Path(file_name).resolve())
         else:
             src_paths.add(Path(file_name).parent.resolve())

     config = Config(**config_dict)

When you fix this, I hope there will still be a way to either (a) use only the configured src_paths and not these dynamically added ones or (b) use only the configured src_paths along with just the one directory of the one file currently being sorted (rather than all the directories of all the files that will be sorted).

All 2 comments

Thanks for reporting! This has been resolved in develop. Note that as you mentioned in another ticket - currently this will be redundant as passed in paths are automatically included in the list of src_paths

Your commit has a bug that accidentally gives me exactly the behavior I want and fixes the huge performance regression (#1239), so I will happily use it鈥攂ut I feel honor-bound to point out that these mutations to src_paths now have no effect on config_dict:

-    src_paths = config_dict.setdefault("src_paths", set())
+    src_paths = set(config_dict.setdefault("src_paths", ()))
     for file_name in file_names:
         if os.path.isdir(file_name):
             src_paths.add(Path(file_name).resolve())
         else:
             src_paths.add(Path(file_name).parent.resolve())

     config = Config(**config_dict)

When you fix this, I hope there will still be a way to either (a) use only the configured src_paths and not these dynamically added ones or (b) use only the configured src_paths along with just the one directory of the one file currently being sorted (rather than all the directories of all the files that will be sorted).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

whg517 picture whg517  路  3Comments

ionelmc picture ionelmc  路  3Comments

johnthagen picture johnthagen  路  3Comments

kevindaum picture kevindaum  路  4Comments

ionelmc picture ionelmc  路  3Comments