Isort: Allow import statement in conditional block

Created on 17 Nov 2017  路  2Comments  路  Source: PyCQA/isort

When the sequence of import statements is interrupted by conditional blocks, ISort thinks the imports have ended and wants the conditional block to be separated from other import statements.

Given this correctly-ordered code:

import pytz
try:
    import semver
except ImportError:
    # We won't be able to parse Semantic Versioning values.
    semver = NotImplemented

ISort mandates these changes:

 import pytz
+
+
 try:
     import semver
 except ImportError:
    # We won't be able to parse Semantic Versioning values.
    semver = NotImplemented

I can't find any way to tell ISort to allow the conditional block (whether try, or if, etc.) as part of the sequence of import statements.

enhancement

Most helpful comment

This behavior has been improved in develop and should make it's way into the 5.0.0 release.

Thanks!

~Timothy

All 2 comments

I also vote for this feature! =)

Ref:

+++ update_cosmosdb_document_python/update_cosmosdb_document/cli.py:after   2019-08-23 22:14:01.322106
@@ -6,7 +6,7 @@
 from typing import Any

 # Non-standard library python package imports
-from azure.cosmos.cosmos_client import CosmosClient      # type: ignore
+from azure.cosmos.cosmos_client import CosmosClient  # type: ignore
 from click import (
     command,
     echo,
@@ -15,11 +15,6 @@
     progressbar,
     version_option,
 )
-try:
-    from IPython import embed    # type: ignore
-except ImportError:
-    def embed():
-        pass

 # Internal module package imports

This behavior has been improved in develop and should make it's way into the 5.0.0 release.

Thanks!

~Timothy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akaihola picture akaihola  路  3Comments

johnthagen picture johnthagen  路  3Comments

pawamoy picture pawamoy  路  3Comments

donjar picture donjar  路  3Comments

pradyunsg picture pradyunsg  路  3Comments