nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: timothycrosley/isort
Pull request #854 (2019-02-27 13:29:28)

Fix bug with parsing WrapModes from config file
Currently `isort` crashes trying to parse `multi_line_output` from a config file due to the fact that `WrapModes(str)` is not a valid `str -> type instance` callable. 


Patch:
diff --git a/isort/settings.py b/isort/settings.py
index c1d17802..aac9d50d 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -32,7 +32,7 @@ import stat
 import warnings
 from distutils.util import strtobool
 from functools import lru_cache
-from typing import Any, Dict, Iterable, List, Mapping, MutableMapping, Type
+from typing import Any, Dict, Iterable, List, Mapping, MutableMapping, Callable
 
 from .utils import difference, union
 
@@ -216,6 +216,13 @@ def _update_settings_with_config(
         _update_with_config_file(editor_config_file, sections, computed_settings)
 
 
+def _get_str_to_type_converter(setting_name: str) -> Callable[[str], Any]:
+    type_converter = type(default.get(setting_name, ''))  # type: Callable[[str], Any]
+    if type_converter == WrapModes:
+        type_converter = WrapModes.from_string
+    return type_converter
+
+
 def _update_with_config_file(
     file_path: str,
     sections: Iterable[str],
@@ -243,7 +250,7 @@ def _update_with_config_file(
 
     for key, value in settings.items():
         access_key = key.replace('not_', '').lower()
-        existing_value_type = type(default.get(access_key, ''))  # type: Type[Any]
+        existing_value_type = _get_str_to_type_converter(access_key)
         if existing_value_type in (list, tuple):
             # sections has fixed order values; no adding or substraction from any set
             if access_key == 'sections':


Test patch:
diff --git a/test_isort.py b/test_isort.py
index b35d6cdd..e7f03d0d 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -26,6 +26,7 @@ import os.path
 import sys
 import sysconfig
 
+import py
 import pytest
 
 from isort import finders, main, settings
@@ -2772,3 +2773,16 @@ def test_noqa_issue_679():
                    'import zed # NOQA\n'
                    'import ujson # NOQA\n')
     assert SortImports(file_contents=test_input).output == test_output
+
+
+def test_extract_multiline_output_wrap_setting_from_a_config_file(tmpdir: py.path.local) -> None:
+    editorconfig_contents = [
+        'root = true',
+        ' [*.py]',
+        'multi_line_output = 5'
+    ]
+    config_file = tmpdir.join('.editorconfig')
+    config_file.write('\n'.join(editorconfig_contents))
+
+    config = settings.from_path(str(tmpdir))
+    assert config['multi_line_output'] == WrapModes.VERTICAL_GRID_GROUPED
Repository: timothycrosley/isort
Pull request #894 (2019-03-09 08:14:12)

Feature/fix skip of star dir glob


Patch:
diff --git a/isort/settings.py b/isort/settings.py
index b1075148..336d0b1e 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -344,7 +344,7 @@ def should_skip(filename, config, path=''):
         position = os.path.split(position[0])
 
     for glob in config['skip_glob']:
-        if fnmatch.fnmatch(filename, glob):
+        if fnmatch.fnmatch(filename, glob) or fnmatch.fnmatch('/' + filename, glob):
             return True
 
     if not (os.path.isfile(os_path) or os.path.isdir(os_path) or os.path.islink(os_path)):


Test patch:
diff --git a/test_isort.py b/test_isort.py
index 998f32c5..58d27d17 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2782,7 +2782,8 @@ def test_safety_excludes(tmpdir, enabled):
     assert file_names == {'verysafe.py'}
 
 
-@pytest.mark.parametrize('skip_glob_assert', (([], 0, {os.sep.join(('code', 'file.py'))}), (['**/*.py'], 1, {})))
+@pytest.mark.parametrize('skip_glob_assert', (([], 0, {os.sep.join(('code', 'file.py'))}), (['**/*.py'], 1, {}),
+                                              (['*/code/*.py'], 1, {})))
 def test_skip_glob(tmpdir, skip_glob_assert):
     skip_glob, skipped_count, file_names = skip_glob_assert
     base_dir = tmpdir.mkdir('build')
Repository: timothycrosley/isort
Pull request #1099 (2020-01-14 06:50:43)

Feature/fix issue 1091


Patch:
diff --git a/isort/output.py b/isort/output.py
index 4343f71a..f7a4b2f7 100644
--- a/isort/output.py
+++ b/isort/output.py
@@ -333,18 +333,18 @@ def _with_from_imports(
                         )
                     comments = None
             else:
+                above_comments = parsed.categorized_comments["above"]["from"].pop(module, None)
+                if above_comments:
+                    if new_section_output and config.ensure_newline_before_comments:
+                        new_section_output.append("")
+                    new_section_output.extend(above_comments)
+
                 while from_imports and from_imports[0] in as_imports:
                     from_import = from_imports.pop(0)
                     as_imports[from_import] = sorting.naturally(as_imports[from_import])
                     from_comments = parsed.categorized_comments["straight"].get(
                         f"{module}.{from_import}"
                     )
-                    above_comments = parsed.categorized_comments["above"]["from"].pop(module, None)
-                    if above_comments:
-                        if new_section_output and config.ensure_newline_before_comments:
-                            new_section_output.append("")
-                        new_section_output.extend(above_comments)
-
                     if (
                         config.keep_direct_and_as_imports
                         and parsed.imports[section]["from"][module][from_import]
@@ -399,13 +399,6 @@ def _with_from_imports(
                         single_import_line += (
                             f"{comments and ';' or config.comment_prefix} " f"{comment}"
                         )
-                        above_comments = parsed.categorized_comments["above"]["from"].pop(
-                            module, None
-                        )
-                        if above_comments:
-                            if new_section_output and config.ensure_newline_before_comments:
-                                new_section_output.append("")
-                            new_section_output.extend(above_comments)
                         new_section_output.append(
                             wrap.line(single_import_line, parsed.line_separator, config)
                         )


Test patch:
diff --git a/tests/test_isort.py b/tests/test_isort.py
index a0f5dfc0..2580fae7 100644
--- a/tests/test_isort.py
+++ b/tests/test_isort.py
@@ -4771,3 +4771,15 @@ try:
      import bar
 """
     assert SortImports(file_contents=test_input).output == test_input
+
+
+def test_comments_top_of_file():
+    """Test to ensure comments at top of file are correctly handled. See issue #1091."""
+    test_input = """# comment 1
+
+# comment 2
+# comment 3
+# comment 4
+from foo import *
+"""
+    assert SortImports(file_contents=test_input).output == test_input
Repository: timothycrosley/isort
Pull request #1108 (2020-01-20 05:01:38)

Feature/fix issue 807


Patch:
diff --git a/isort/output.py b/isort/output.py
index f7a4b2f7..035224c9 100644
--- a/isort/output.py
+++ b/isort/output.py
@@ -34,12 +34,16 @@ def sorted_imports(
 
     if config.no_sections:
         parsed.imports["no_sections"] = {"straight": [], "from": {}}
+        base_sections: Tuple[str, ...] = ()
         for section in sections:
+            if section == "FUTURE":
+                base_sections = ("FUTURE",)
+                continue
             parsed.imports["no_sections"]["straight"].extend(
                 parsed.imports[section].get("straight", [])
             )
             parsed.imports["no_sections"]["from"].update(parsed.imports[section].get("from", {}))
-        sections = ("no_sections",)
+        sections = base_sections + ("no_sections",)
 
     output: List[str] = []
     pending_lines_before = False


Test patch:
diff --git a/tests/test_isort.py b/tests/test_isort.py
index aef14e32..107a3f62 100644
--- a/tests/test_isort.py
+++ b/tests/test_isort.py
@@ -4850,3 +4850,15 @@ from datetime import datetime as dt
         SortImports(file_contents=test_input, keep_direct_and_as_imports=True).output
         == expected_output
     )
+
+
+def test_no_sections_with_future():
+    """Test to ensure no_sections works with future. See issue #807"""
+    test_input = """from __future__ import print_function
+import os
+    """
+    expected_output = """from __future__ import print_function
+
+import os
+"""
+    assert SortImports(file_contents=test_input, no_sections=True).output == expected_output
Repository: timothycrosley/isort
Pull request #1131 (2020-02-10 22:51:32)

Fix issue with as_imports and force_single_section
Fixes issue with as_imports and force_single_section


Patch:
diff --git a/isort/output.py b/isort/output.py
index 035224c9..8b753bcd 100644
--- a/isort/output.py
+++ b/isort/output.py
@@ -33,14 +33,14 @@ def sorted_imports(
     sections: Iterable[str] = itertools.chain(parsed.sections, config.forced_separate)
 
     if config.no_sections:
-        parsed.imports["no_sections"] = {"straight": [], "from": {}}
+        parsed.imports["no_sections"] = {"straight": {}, "from": {}}
         base_sections: Tuple[str, ...] = ()
         for section in sections:
             if section == "FUTURE":
                 base_sections = ("FUTURE",)
                 continue
-            parsed.imports["no_sections"]["straight"].extend(
-                parsed.imports[section].get("straight", [])
+            parsed.imports["no_sections"]["straight"].update(
+                parsed.imports[section].get("straight", {})
             )
             parsed.imports["no_sections"]["from"].update(parsed.imports[section].get("from", {}))
         sections = base_sections + ("no_sections",)


Test patch:
diff --git a/tests/test_isort.py b/tests/test_isort.py
index d3fc6a33..88d4349a 100644
--- a/tests/test_isort.py
+++ b/tests/test_isort.py
@@ -4920,6 +4920,14 @@ import os
     assert SortImports(file_contents=test_input, no_sections=True).output == expected_output
 
 
+def test_no_sections_with_as_import():
+    """Test to ensure no_sections work with as import."""
+    test_input = """import oumpy as np
+import sympy
+"""
+    assert SortImports(file_contents=test_input, no_sections=True).output == test_input
+
+
 def test_no_lines_too_long():
     """Test to ensure no lines end up too long. See issue: #1015"""
     test_input = """from package1 import first_package, \
Repository: timothycrosley/isort
Pull request #1138 (2020-02-12 21:16:09)

Fix Config instance copy mechanism


Patch:
diff --git a/isort/settings.py b/isort/settings.py
index 9427ee1e..8a661c3e 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -212,7 +212,7 @@ class Config(_Config):
         **config_overrides,
     ):
         if config:
-            config_vars = vars(config)
+            config_vars = vars(config).copy()
             config_vars.update(config_overrides)
             config_vars["py_version"] = config_vars["py_version"].replace("py", "")
             return super().__init__(**config_vars)  # type: ignore


Test patch:
diff --git a/tests/test_isort.py b/tests/test_isort.py
index bfd1445b..4aadcc9e 100644
--- a/tests/test_isort.py
+++ b/tests/test_isort.py
@@ -523,6 +523,20 @@ def test_output_modes() -> None:
         "        BasicTextFieldEmbedder"
     )
 
+    test_input = (
+        "class A:\n"
+        "    def a():\n"
+        "        from allennlp.common.registrable import Registrable"
+        "  # import here to avoid circular imports\n"
+        "\n\n"
+        "class B:\n"
+        "    def b():\n"
+        "        from allennlp.common.registrable import Registrable"
+        "  # import here to avoid circular imports\n"
+    )
+    test_output = SortImports(file_contents=test_input, line_length=100).output
+    assert test_output == test_input
+
 
 def test_qa_comment_case() -> None:
     test_input = "from veryveryveryveryveryveryveryveryveryveryvery import X  # NOQA"