Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noqa comment is moved from star import to constant import #1427

Closed
jparise opened this issue Aug 28, 2020 · 6 comments · Fixed by #1430
Closed

noqa comment is moved from star import to constant import #1427

jparise opened this issue Aug 28, 2020 · 6 comments · Fixed by #1430
Labels
bug Something isn't working
Milestone

Comments

@jparise
Copy link
Member

jparise commented Aug 28, 2020

Given:

from package import CONSTANT
from package import *  # noqa

isort will relocate the # noqa comment to the first line:

from package import CONSTANT  # noqa
from package import *

... which obviously breaks things.

@jparise
Copy link
Member Author

jparise commented Aug 28, 2020

And yes, this is a weird import pattern. 😉

@timothycrosley
Copy link
Member

Hi @jparise,

Thanks for reporting! Sorry you are experiencing this! Weird pattern or not isort should not move your comments. I'm having trouble reproducing this, would you be willing to provide the output of isort --show-config and verify you are using the latest version of isort?

Thanks!

~Timothy

@timothycrosley timothycrosley added the repo_needed Can't currently reproduce, if reproduction steps are added we will resivit this issue. label Aug 28, 2020
@jparise
Copy link
Member Author

jparise commented Aug 28, 2020

I tracked it down to the force_single_line option. With force_single_line = true (and an otherwise empty pyproject.toml configuration), it misbehaves as reported:

@@ -1,2 +1,2 @@
-from package import CONSTANT
-from package import *  # noqa
+from package import CONSTANT  # noqa
+from package import *

With an empty configuration (which implies force_single_line = false), it will sort the like this:

@@ -1,2 +1,2 @@
+from package import *  # noqa
 from package import CONSTANT
-from package import *  # noqa

Here's the full configuration:

{
    "_known_patterns": null,
    "_section_comments": null,
    "py_version": "py3",
    "force_to_top": [],
    "skip": [
        "buck-out",
        ".eggs",
        ".hg",
        ".nox",
        ".mypy_cache",
        "_build",
        "venv",
        "dist",
        ".pants.d",
        "build",
        "node_modules",
        ".tox",
        ".venv",
        ".git"
    ],
    "skip_glob": [],
    "skip_gitignore": false,
    "line_length": 79,
    "wrap_length": 0,
    "line_ending": "",
    "sections": [
        "FUTURE",
        "STDLIB",
        "THIRDPARTY",
        "FIRSTPARTY",
        "LOCALFOLDER"
    ],
    "no_sections": false,
    "known_future_library": [
        "__future__"
    ],
    "known_third_party": [],
    "known_first_party": [],
    "known_local_folder": [],
    "known_standard_library": [
        "fpectl",
        "pipes",
        "contextvars",
        "encodings",
        "parser",
        "getopt",
        "unicodedata",
        "asyncore",
        "ctypes",
        "test",
        "zlib",
        "pwd",
        "typing",
        "types",
        "cgi",
        "subprocess",
        "py_compile",
        "colorsys",
        "code",
        "email",
        "ssl",
        "compileall",
        "aifc",
        "cmath",
        "unittest",
        "sunau",
        "enum",
        "glob",
        "posixpath",
        "imghdr",
        "turtle",
        "webbrowser",
        "base64",
        "math",
        "bisect",
        "bz2",
        "_thread",
        "numbers",
        "xml",
        "codecs",
        "itertools",
        "dis",
        "sqlite3",
        "tabnanny",
        "audioop",
        "gc",
        "pty",
        "logging",
        "macpath",
        "functools",
        "filecmp",
        "smtplib",
        "queue",
        "hmac",
        "mailcap",
        "syslog",
        "ensurepip",
        "pickle",
        "socketserver",
        "nis",
        "plistlib",
        "collections",
        "contextlib",
        "asynchat",
        "getpass",
        "timeit",
        "msilib",
        "mimetypes",
        "sched",
        "traceback",
        "errno",
        "symbol",
        "configparser",
        "os",
        "doctest",
        "turtledemo",
        "gzip",
        "uu",
        "copy",
        "pstats",
        "hashlib",
        "sre_constants",
        "mmap",
        "keyword",
        "codeop",
        "wave",
        "pdb",
        "modulefinder",
        "winsound",
        "stat",
        "shlex",
        "locale",
        "winreg",
        "dummy_threading",
        "inspect",
        "io",
        "lib2to3",
        "calendar",
        "copyreg",
        "gettext",
        "shelve",
        "pydoc",
        "wsgiref",
        "termios",
        "threading",
        "runpy",
        "_dummy_thread",
        "difflib",
        "rlcompleter",
        "binhex",
        "asyncio",
        "atexit",
        "builtins",
        "heapq",
        "resource",
        "warnings",
        "telnetlib",
        "tokenize",
        "abc",
        "readline",
        "reprlib",
        "pkgutil",
        "xdrlib",
        "pprint",
        "argparse",
        "sre_parse",
        "weakref",
        "stringprep",
        "cProfile",
        "sysconfig",
        "cmd",
        "site",
        "random",
        "tty",
        "distutils",
        "grp",
        "textwrap",
        "msvcrt",
        "secrets",
        "concurrent",
        "pathlib",
        "urllib",
        "posix",
        "curses",
        "signal",
        "json",
        "tempfile",
        "faulthandler",
        "re",
        "mailbox",
        "ipaddress",
        "tarfile",
        "fcntl",
        "symtable",
        "ftplib",
        "linecache",
        "html",
        "xmlrpc",
        "multiprocessing",
        "datetime",
        "ast",
        "netrc",
        "decimal",
        "profile",
        "dbm",
        "formatter",
        "imp",
        "sre_compile",
        "zipimport",
        "time",
        "struct",
        "chunk",
        "optparse",
        "importlib",
        "fractions",
        "crypt",
        "sre",
        "tracemalloc",
        "string",
        "pickletools",
        "sndhdr",
        "pyclbr",
        "array",
        "marshal",
        "shutil",
        "tkinter",
        "trace",
        "lzma",
        "csv",
        "fnmatch",
        "selectors",
        "smtpd",
        "uuid",
        "fileinput",
        "platform",
        "http",
        "imaplib",
        "binascii",
        "nntplib",
        "token",
        "zipfile",
        "dataclasses",
        "ntpath",
        "zipapp",
        "ossaudiodev",
        "poplib",
        "statistics",
        "venv",
        "spwd",
        "socket",
        "operator",
        "sys",
        "cgitb",
        "quopri",
        "select",
        "bdb"
    ],
    "extra_standard_library": [],
    "known_other": {},
    "multi_line_output": "GRID",
    "forced_separate": [],
    "indent": "    ",
    "comment_prefix": "  #",
    "length_sort": false,
    "length_sort_straight": false,
    "length_sort_sections": [],
    "add_imports": [],
    "remove_imports": [],
    "append_only": false,
    "reverse_relative": false,
    "force_single_line": true,
    "single_line_exclusions": [],
    "default_section": "THIRDPARTY",
    "import_headings": {},
    "balanced_wrapping": false,
    "use_parentheses": false,
    "order_by_type": true,
    "atomic": false,
    "lines_after_imports": -1,
    "lines_between_sections": 1,
    "lines_between_types": 0,
    "combine_as_imports": false,
    "combine_star": false,
    "include_trailing_comma": false,
    "from_first": false,
    "verbose": false,
    "quiet": false,
    "force_adds": false,
    "force_alphabetical_sort_within_sections": false,
    "force_alphabetical_sort": false,
    "force_grid_wrap": 0,
    "force_sort_within_sections": false,
    "lexicographical": false,
    "ignore_whitespace": false,
    "no_lines_before": [],
    "no_inline_sort": false,
    "ignore_comments": false,
    "case_sensitive": false,
    "sources": [
        {
            "py_version": "py3",
            "force_to_top": [],
            "skip": [
                "buck-out",
                ".eggs",
                ".hg",
                ".nox",
                ".mypy_cache",
                "_build",
                "venv",
                "dist",
                ".pants.d",
                "build",
                "node_modules",
                ".tox",
                ".venv",
                ".git"
            ],
            "skip_glob": [],
            "skip_gitignore": false,
            "line_length": 79,
            "wrap_length": 0,
            "line_ending": "",
            "sections": [
                "FUTURE",
                "STDLIB",
                "THIRDPARTY",
                "FIRSTPARTY",
                "LOCALFOLDER"
            ],
            "no_sections": false,
            "known_future_library": [
                "__future__"
            ],
            "known_third_party": [],
            "known_first_party": [],
            "known_local_folder": [],
            "known_standard_library": [
                "fpectl",
                "pipes",
                "contextvars",
                "encodings",
                "parser",
                "getopt",
                "unicodedata",
                "asyncore",
                "ctypes",
                "test",
                "zlib",
                "pwd",
                "typing",
                "types",
                "cgi",
                "subprocess",
                "py_compile",
                "colorsys",
                "code",
                "email",
                "ssl",
                "compileall",
                "aifc",
                "cmath",
                "unittest",
                "sunau",
                "enum",
                "glob",
                "posixpath",
                "imghdr",
                "turtle",
                "webbrowser",
                "base64",
                "math",
                "bisect",
                "bz2",
                "_thread",
                "numbers",
                "xml",
                "codecs",
                "itertools",
                "dis",
                "sqlite3",
                "tabnanny",
                "audioop",
                "gc",
                "pty",
                "logging",
                "macpath",
                "functools",
                "filecmp",
                "smtplib",
                "queue",
                "hmac",
                "mailcap",
                "syslog",
                "ensurepip",
                "pickle",
                "socketserver",
                "nis",
                "plistlib",
                "collections",
                "contextlib",
                "asynchat",
                "getpass",
                "timeit",
                "msilib",
                "mimetypes",
                "sched",
                "traceback",
                "errno",
                "symbol",
                "configparser",
                "os",
                "doctest",
                "turtledemo",
                "gzip",
                "uu",
                "copy",
                "pstats",
                "hashlib",
                "sre_constants",
                "mmap",
                "keyword",
                "codeop",
                "wave",
                "pdb",
                "modulefinder",
                "winsound",
                "stat",
                "shlex",
                "locale",
                "winreg",
                "dummy_threading",
                "inspect",
                "io",
                "lib2to3",
                "calendar",
                "copyreg",
                "gettext",
                "shelve",
                "pydoc",
                "wsgiref",
                "termios",
                "threading",
                "runpy",
                "_dummy_thread",
                "difflib",
                "rlcompleter",
                "binhex",
                "asyncio",
                "atexit",
                "builtins",
                "heapq",
                "resource",
                "warnings",
                "telnetlib",
                "tokenize",
                "abc",
                "readline",
                "reprlib",
                "pkgutil",
                "xdrlib",
                "pprint",
                "argparse",
                "sre_parse",
                "weakref",
                "stringprep",
                "cProfile",
                "sysconfig",
                "cmd",
                "site",
                "random",
                "tty",
                "distutils",
                "grp",
                "textwrap",
                "msvcrt",
                "secrets",
                "concurrent",
                "pathlib",
                "urllib",
                "posix",
                "curses",
                "signal",
                "json",
                "tempfile",
                "faulthandler",
                "re",
                "mailbox",
                "ipaddress",
                "tarfile",
                "fcntl",
                "symtable",
                "ftplib",
                "linecache",
                "html",
                "xmlrpc",
                "multiprocessing",
                "datetime",
                "ast",
                "netrc",
                "decimal",
                "profile",
                "dbm",
                "formatter",
                "imp",
                "sre_compile",
                "zipimport",
                "time",
                "struct",
                "chunk",
                "optparse",
                "importlib",
                "fractions",
                "crypt",
                "sre",
                "tracemalloc",
                "string",
                "pickletools",
                "sndhdr",
                "pyclbr",
                "array",
                "marshal",
                "shutil",
                "tkinter",
                "trace",
                "lzma",
                "csv",
                "fnmatch",
                "selectors",
                "smtpd",
                "uuid",
                "fileinput",
                "platform",
                "http",
                "imaplib",
                "binascii",
                "nntplib",
                "token",
                "zipfile",
                "dataclasses",
                "ntpath",
                "zipapp",
                "ossaudiodev",
                "poplib",
                "statistics",
                "venv",
                "spwd",
                "socket",
                "operator",
                "sys",
                "cgitb",
                "quopri",
                "select",
                "bdb"
            ],
            "extra_standard_library": [],
            "known_other": {},
            "multi_line_output": "GRID",
            "forced_separate": [],
            "indent": "    ",
            "comment_prefix": "  #",
            "length_sort": false,
            "length_sort_straight": false,
            "length_sort_sections": [],
            "add_imports": [],
            "remove_imports": [],
            "append_only": false,
            "reverse_relative": false,
            "force_single_line": false,
            "single_line_exclusions": [],
            "default_section": "THIRDPARTY",
            "import_headings": {},
            "balanced_wrapping": false,
            "use_parentheses": false,
            "order_by_type": true,
            "atomic": false,
            "lines_after_imports": -1,
            "lines_between_sections": 1,
            "lines_between_types": 0,
            "combine_as_imports": false,
            "combine_star": false,
            "include_trailing_comma": false,
            "from_first": false,
            "verbose": false,
            "quiet": false,
            "force_adds": false,
            "force_alphabetical_sort_within_sections": false,
            "force_alphabetical_sort": false,
            "force_grid_wrap": 0,
            "force_sort_within_sections": false,
            "lexicographical": false,
            "ignore_whitespace": false,
            "no_lines_before": [],
            "no_inline_sort": false,
            "ignore_comments": false,
            "case_sensitive": false,
            "sources": [],
            "virtual_env": "",
            "conda_env": "",
            "ensure_newline_before_comments": false,
            "directory": "",
            "profile": "",
            "honor_noqa": false,
            "src_paths": [],
            "old_finders": false,
            "remove_redundant_aliases": false,
            "float_to_top": false,
            "filter_files": false,
            "formatter": "",
            "formatting_function": null,
            "color_output": false,
            "treat_comments_as_code": [],
            "treat_all_comments_as_code": false,
            "supported_extensions": [
                "py",
                "pyx",
                "pyi"
            ],
            "blocked_extensions": [
                "pex"
            ],
            "constants": [],
            "classes": [],
            "variables": [],
            "dedup_headings": false,
            "source": "defaults"
        },
        {
            "force_single_line": true,
            "source": "/Users/jon/Work/isort/pyproject.toml"
        }
    ],
    "virtual_env": "",
    "conda_env": "",
    "ensure_newline_before_comments": false,
    "directory": "/Users/jon/Work/isort",
    "profile": "",
    "honor_noqa": false,
    "src_paths": [
        "/Users/jon/Work/isort/src",
        "/Users/jon/Work/isort"
    ],
    "old_finders": false,
    "remove_redundant_aliases": false,
    "float_to_top": false,
    "filter_files": false,
    "formatter": "",
    "formatting_function": null,
    "color_output": false,
    "treat_comments_as_code": [],
    "treat_all_comments_as_code": false,
    "supported_extensions": [
        "py",
        "pyx",
        "pyi"
    ],
    "blocked_extensions": [
        "pex"
    ],
    "constants": [],
    "classes": [],
    "variables": [],
    "dedup_headings": false
}

@timothycrosley timothycrosley added bug Something isn't working and removed repo_needed Can't currently reproduce, if reproduction steps are added we will resivit this issue. labels Aug 28, 2020
@timothycrosley
Copy link
Member

Thanks for the additional information! Using the setting provided I've been able to reproduce the issue and will be prioritizing fixing it and adding it to the isort test suite.

~Timothy

@timothycrosley
Copy link
Member

This has been fixed in develop and will be deployed to PyPI in the 5.5.0 release slated for September 1st, or earlier.

Thanks!

~Timothy

@timothycrosley
Copy link
Member

A fix for this issue has just been deployed to PyPI in version 5.5.0 of isort. A couple of days late on the release, but better late then never :)

Thanks!

~Timothy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants