[tor-commits] [stem/master] Replace 'as' imports with 'from'

atagar at torproject.org atagar at torproject.org
Sun Nov 17 23:40:39 UTC 2019


commit ef25411f33aabe4348255e1619cae15803e41221
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Oct 11 10:09:14 2019 -0700

    Replace 'as' imports with 'from'
    
    The following import statements should be the same...
    
      import stem.descriptor.hsv3_crypto as hsv3_crypto
      from stem.descriptor import hsv3_crypto
    
    However, for reasons I don't really grok the former errors for me with both
    python 2.7 and 3.4...
    
      % ./run_tests.py --all
      Traceback (most recent call last):
        File "./run_tests.py", line 36, in <module>
          import test.runner
        File "/home/atagar/Desktop/stem/test/runner.py", line 44, in <module>
          import stem.connection
        File "/home/atagar/Desktop/stem/stem/connection.py", line 136, in <module>
          import stem.control
        File "/home/atagar/Desktop/stem/stem/control.py", line 271, in <module>
          import stem.descriptor.microdescriptor
        File "/home/atagar/Desktop/stem/stem/descriptor/__init__.py", line 1542, in <module>
          import stem.descriptor.hidden_service
        File "/home/atagar/Desktop/stem/stem/descriptor/hidden_service.py", line 46, in <module>
          import stem.descriptor.hsv3_crypto as hsv3_crypto
        File "/home/atagar/Desktop/stem/stem/descriptor/hsv3_crypto.py", line 11, in <module>
          import stem.descriptor.ed25519_exts_ref as ed25519_exts_ref
      AttributeError: 'module' object has no attribute 'descriptor'
    
    Replacing this with 'from' imports does the trick. I'm not gonna worry too much
    about why, as we should use 'from' over 'as' for consistency with the rest of
    the codebase anyway.
---
 stem/descriptor/hidden_service.py | 4 ++--
 stem/descriptor/hsv3_crypto.py    | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/stem/descriptor/hidden_service.py b/stem/descriptor/hidden_service.py
index 3601adcf..5f97a25a 100644
--- a/stem/descriptor/hidden_service.py
+++ b/stem/descriptor/hidden_service.py
@@ -43,7 +43,7 @@ import stem.util.connection
 import stem.util.str_tools
 import stem.util.tor_tools
 
-import stem.descriptor.hsv3_crypto as hsv3_crypto
+from stem.descriptor import hsv3_crypto
 
 from stem.descriptor.certificate import Ed25519Certificate, CertType
 
@@ -781,7 +781,7 @@ class HiddenServiceDescriptorV2(BaseHiddenServiceDescriptor):
     return introduction_points
 
 import stem.descriptor.certificate
-import stem.descriptor.hsv3_crypto as hsv3_crypto
+from stem.descriptor import hsv3_crypto
 from cryptography.hazmat.primitives import serialization
 from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
 from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey
diff --git a/stem/descriptor/hsv3_crypto.py b/stem/descriptor/hsv3_crypto.py
index 275450c0..6665a880 100644
--- a/stem/descriptor/hsv3_crypto.py
+++ b/stem/descriptor/hsv3_crypto.py
@@ -3,14 +3,14 @@ import hashlib
 import struct
 import os
 
+from stem.descriptor import ed25519_exts_ref
+from stem.descriptor import slow_ed25519
+
 from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
 from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
 from cryptography.hazmat.backends import default_backend
 from cryptography.hazmat.primitives import serialization
 
-import stem.descriptor.ed25519_exts_ref as ed25519_exts_ref
-import stem.descriptor.slow_ed25519 as slow_ed25519
-
 def pubkeys_are_equal(pubkey1, pubkey2):
     """
     Compare the raw bytes of the two pubkeys and return True if they are the same





More information about the tor-commits mailing list