Commits

Patrick Mézard  committed 1ba3a64

Fix module imports with demandimport

demandimport behaves unexpectedly when you write something like:

try:
from foo.bar import someclass
except ImportError:
# do something else

If foo.bar does exist but does not contain "someclass", demandimport returns a
lazy module object instead of raising ImportError. The solution is to force the
non-module symbols to be loaded by accessing them like:

try:
import foo.bar
someclass = foo.bar.someclass
except (ImportError, AttributeError):
# do something else

  • Participants
  • Parent commits 476937a

Comments (0)

Files changed (1)

File mercurial_keyring.py

         except AttributeError:
             try:
                 # hg 1.8
-                from mercurial.url import readauthforuri
-            except ImportError:
+                import mercurial.url
+                readauthforuri = mercurial.url.readauthforuri
+            except (ImportError, AttributeError):
                 # hg 1.9
-                from mercurial.httpconnection import readauthforuri
+                import mercurial.httpconnection
+                readauthforuri = mercurial.httpconnection.readauthforuri
             res = readauthforuri(local_ui, base_url)
             if res:
                 group, auth_token = res