Skip to content

Commit

Permalink
Fixed #1192: or option has been deprecated as it is now always on.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 15, 2020
1 parent fd87001 commit 0d37ec2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 282 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ NOTE: isort follows the [semver](https://semver.org/) versioning standard.
- Implemented support for automatic redundant alias removal (issue #1281).
- Fixed #1178: support for semicolons in decorators.
- Fixed #1315: Extra newline before comment with -n + --fss.
- Fixed #1192: `-k` or `--keep-direct-and-as-imports` option has been deprecated as it is now always on.

**Formatting changes implied:**
- Fixed #1280: rewrite of as imports changes the behavior of the imports.
Expand Down
18 changes: 9 additions & 9 deletions isort/main.py
Expand Up @@ -289,13 +289,6 @@ def _build_arg_parser() -> argparse.ArgumentParser:
parser.add_argument(
"-j", "--jobs", help="Number of files to process in parallel.", dest="jobs", type=int
)
parser.add_argument(
"-k",
"--keep-direct-and-as",
dest="keep_direct_and_as_imports",
action="store_true",
help="Turns off default behavior that removes direct imports when as imports exist.",
)
parser.add_argument("--lai", "--lines-after-imports", dest="lines_after_imports", type=int)
parser.add_argument("--lbt", "--lines-between-types", dest="lines_between_types", type=int)
parser.add_argument(
Expand Down Expand Up @@ -621,10 +614,17 @@ def _build_arg_parser() -> argparse.ArgumentParser:
"--apply",
dest="deprecated_flags",
action="append_const",
const="-y",
const="--apply",
help=argparse.SUPPRESS,
)
parser.add_argument(
"-k",
"--keep-direct-and-as",
dest="deprecated_flags",
action="append_const",
const="--keep-direct-and-as",
help=argparse.SUPPRESS,
)

return parser


Expand Down
22 changes: 5 additions & 17 deletions isort/output.py
Expand Up @@ -267,10 +267,7 @@ def _with_from_imports(
for from_import in copy.copy(from_imports):
if from_import in as_imports:
idx = from_imports.index(from_import)
if (
config.keep_direct_and_as_imports
and parsed.imports[section]["from"][module][from_import]
):
if parsed.imports[section]["from"][module][from_import]:
from_imports[(idx + 1) : (idx + 1)] = as_imports.pop(from_import)
else:
from_imports[idx : (idx + 1)] = as_imports.pop(from_import)
Expand Down Expand Up @@ -313,10 +310,7 @@ def _with_from_imports(
f"{comments and ';' or config.comment_prefix} " f"{comment}"
)
if from_import in as_imports:
if (
config.keep_direct_and_as_imports
and parsed.imports[section]["from"][module][from_import]
):
if parsed.imports[section]["from"][module][from_import]:
new_section_output.append(
wrap.line(single_import_line, parsed.line_separator, config)
)
Expand Down Expand Up @@ -344,10 +338,7 @@ def _with_from_imports(
from_comments = parsed.categorized_comments["straight"].get(
f"{module}.{from_import}"
)
if (
config.keep_direct_and_as_imports
and parsed.imports[section]["from"][module][from_import]
):
if parsed.imports[section]["from"][module][from_import]:
new_section_output.append(
with_comments(
from_comments,
Expand Down Expand Up @@ -383,8 +374,6 @@ def _with_from_imports(
comments = None

for from_import in copy.copy(from_imports):
if from_import in as_imports and not config.keep_direct_and_as_imports:
continue
comment = (
parsed.categorized_comments["nested"].get(module, {}).pop(from_import, None)
)
Expand All @@ -408,8 +397,7 @@ def _with_from_imports(
while from_imports and (
from_imports[0] not in as_imports
or (
config.keep_direct_and_as_imports
and config.combine_as_imports
config.combine_as_imports
and parsed.imports[section]["from"][module][from_import]
)
):
Expand Down Expand Up @@ -488,7 +476,7 @@ def _with_straight_imports(

import_definition = []
if module in parsed.as_map["straight"]:
if config.keep_direct_and_as_imports and parsed.imports[section]["straight"][module]:
if parsed.imports[section]["straight"][module]:
import_definition.append(f"{import_type} {module}")
import_definition.extend(
f"{import_type} {module} as {as_import}"
Expand Down
3 changes: 1 addition & 2 deletions isort/settings.py
Expand Up @@ -61,7 +61,7 @@

RUNTIME_SOURCE = "runtime"

DEPRECATED_SETTINGS = ("not_skip",)
DEPRECATED_SETTINGS = ("not_skip", "keep_direct_and_as_imports")

_STR_BOOLEAN_MAPPING = {
"y": True,
Expand Down Expand Up @@ -141,7 +141,6 @@ class _Config:
lines_between_types: int = 0
combine_as_imports: bool = False
combine_star: bool = False
keep_direct_and_as_imports: bool = True
include_trailing_comma: bool = False
from_first: bool = False
verbose: bool = False
Expand Down

0 comments on commit 0d37ec2

Please sign in to comment.