[tor-commits] [stem/master] Static check fixes

atagar at torproject.org atagar at torproject.org
Sun Oct 18 00:02:00 UTC 2020


commit c6952feecfaef195c6ef6123f5f08ddd770c6aeb
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Oct 17 16:06:17 2020 -0700

    Static check fixes
    
    Upgrading to pycodestyle 2.6.0 produced a few new warnings...
    
      STATIC CHECKS
      * /home/atagar/Desktop/stem/stem/descriptor/certificate.py
        line 257  - undefined name 'cryptography'            | def __init__(self, cert_type: Optional['stem.client.datatype.CertType'] = None, expiration: Optional[datetime.datetime] = None, key_type: Optional[int] = None, key: Optional[bytes] = None, extensions: Optional[Sequence['stem.descriptor.certificate.Ed25519Extension']] = None, signature: Optional[bytes] = None, signing_key: Optional['cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey'] = None) -> None:  # type: ignore
    
      * /home/atagar/Desktop/stem/stem/descriptor/hidden_service.py
        line 288  - E741 ambiguous variable name 'l'         | link_specifiers = link_count + b''.join([l.pack() for l in self.link_specifiers])
    
      * /home/atagar/Desktop/stem/stem/interpreter/commands.py
        line 272  - E741 ambiguous variable name 'l'         | lines += [format(l, *STANDARD_OUTPUT) for l in str(desc).splitlines()]
    
      * /home/atagar/Desktop/stem/stem/util/__init__.py
        line 84   - undefined name 'cryptography'            | def _pubkey_bytes(key: Union['cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey', 'cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey', 'cryptography.hazmat.primitives.asymmetric.x25519.X25519PrivateKey', 'cryptography.hazmat.primitives.asymmetric.x25519.X25519PublicKey']) -> bytes:  # type: ignore
    
      * /home/atagar/Desktop/stem/test/unit/response/events.py
        line 540  - 'stem.control.Controller' imported but unused | from stem.control import Controller, EventType
    
      * stem/client/__init__.py
        line 322  - unused 'type: ignore' comment
    
      * stem/control.py
        line 2493 - Unpacking a string is disallowed  [misc]
        line 2511 - Unpacking a string is disallowed  [misc]
        line 2516 - Unpacking a string is disallowed  [misc]
    
      * stem/directory.py
        line 270  - Unpacking a string is disallowed  [misc]
        line 271  - Unpacking a string is disallowed  [misc]
        line 436  - Unpacking a string is disallowed  [misc]
---
 stem/client/__init__.py           |  2 +-
 stem/control.py                   | 12 +++++++-----
 stem/descriptor/hidden_service.py |  2 +-
 stem/directory.py                 |  6 +++---
 stem/interpreter/commands.py      |  2 +-
 test/settings.cfg                 |  2 ++
 test/unit/response/events.py      |  2 +-
 7 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/stem/client/__init__.py b/stem/client/__init__.py
index 877d60e2..5453f1f2 100644
--- a/stem/client/__init__.py
+++ b/stem/client/__init__.py
@@ -319,7 +319,7 @@ class Circuit(object):
     except ImportError:
       raise ImportError('Circuit construction requires the cryptography module')
 
-    ctr = modes.CTR(ZERO * (algorithms.AES.block_size // 8))  # type: ignore
+    ctr = modes.CTR(ZERO * (algorithms.AES.block_size // 8))
 
     self.relay = relay
     self.id = circ_id
diff --git a/stem/control.py b/stem/control.py
index b889b801..91d1b3ed 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -2488,9 +2488,11 @@ class Controller(BaseController):
     query_comp = ['RESETCONF' if reset else 'SETCONF']
 
     if isinstance(params, dict):
-      params = list(params.items())
+      params_list = list(params.items())
+    else:
+      params_list = params  # type: ignore # type: Sequence[Tuple[str, Union[str, Sequence[str]]]]
 
-    for param, value in params:
+    for param, value in params_list:
       if isinstance(value, str):
         query_comp.append('%s="%s"' % (param, value.strip()))
       elif isinstance(value, collections.Iterable):
@@ -2508,12 +2510,12 @@ class Controller(BaseController):
 
       if self.is_caching_enabled():
         # clear cache for params; the CONF_CHANGED event will set cache for changes
-        to_cache = dict((k.lower(), None) for k, v in params)
+        to_cache = dict((k.lower(), None) for k, v in params_list)
         self._set_cache(to_cache, 'getconf')
-        self._confchanged_cache_invalidation(dict(params))
+        self._confchanged_cache_invalidation(dict(params_list))
     else:
       log.debug('%s (failed, code: %s, message: %s)' % (query, response.code, response.message))
-      immutable_params = [k for k, v in params if stem.util.str_tools._to_unicode(k).lower() in IMMUTABLE_CONFIG_OPTIONS]
+      immutable_params = [k for k, v in params_list if stem.util.str_tools._to_unicode(k).lower() in IMMUTABLE_CONFIG_OPTIONS]
 
       if immutable_params:
         raise stem.InvalidArguments(message = "%s cannot be changed while tor's running" % ', '.join(sorted(immutable_params)), arguments = immutable_params)
diff --git a/stem/descriptor/hidden_service.py b/stem/descriptor/hidden_service.py
index dc86b382..63f107e7 100644
--- a/stem/descriptor/hidden_service.py
+++ b/stem/descriptor/hidden_service.py
@@ -285,7 +285,7 @@ class IntroductionPointV3(collections.namedtuple('IntroductionPointV3', ['link_s
     lines = []
 
     link_count = stem.client.datatype.Size.CHAR.pack(len(self.link_specifiers))
-    link_specifiers = link_count + b''.join([l.pack() for l in self.link_specifiers])
+    link_specifiers = link_count + b''.join([link.pack() for link in self.link_specifiers])
     lines.append('introduction-point %s' % stem.util.str_tools._to_unicode(base64.b64encode(link_specifiers)))
     lines.append('onion-key ntor %s' % self.onion_key_raw)
     lines.append('auth-key\n' + self.auth_key_cert.to_base64(pem = True))
diff --git a/stem/directory.py b/stem/directory.py
index 39abfb90..710e598e 100644
--- a/stem/directory.py
+++ b/stem/directory.py
@@ -267,8 +267,8 @@ class Authority(Directory):
       results = {}
 
       for matches in _directory_entries(lines, Authority._pop_section, (AUTHORITY_NAME, AUTHORITY_V3IDENT, AUTHORITY_IPV6, AUTHORITY_ADDR), required = (AUTHORITY_NAME, AUTHORITY_ADDR)):
-        nickname, or_port = matches.get(AUTHORITY_NAME)
-        address, dir_port, fingerprint = matches.get(AUTHORITY_ADDR)
+        nickname, or_port = matches.get(AUTHORITY_NAME)  # type: ignore
+        address, dir_port, fingerprint = matches.get(AUTHORITY_ADDR)  # type: ignore
 
         results[nickname] = Authority(
           address = address,
@@ -433,7 +433,7 @@ class Fallback(Directory):
       results = {}
 
       for matches in _directory_entries(lines, Fallback._pop_section, (FALLBACK_ADDR, FALLBACK_NICKNAME, FALLBACK_EXTRAINFO, FALLBACK_IPV6), required = (FALLBACK_ADDR,)):
-        address, dir_port, or_port, fingerprint = matches[FALLBACK_ADDR]
+        address, dir_port, or_port, fingerprint = matches[FALLBACK_ADDR]  # type: ignore
 
         results[fingerprint] = Fallback(
           address = address,
diff --git a/stem/interpreter/commands.py b/stem/interpreter/commands.py
index 83fd18ef..8552b055 100644
--- a/stem/interpreter/commands.py
+++ b/stem/interpreter/commands.py
@@ -269,7 +269,7 @@ class ControlInterpreter(code.InteractiveConsole):
     for label, desc in descriptor_section:
       if desc:
         lines += ['', div, format(label, *BOLD_OUTPUT), div, '']
-        lines += [format(l, *STANDARD_OUTPUT) for l in str(desc).splitlines()]
+        lines += [format(line, *STANDARD_OUTPUT) for line in str(desc).splitlines()]
 
     return '\n'.join(lines)
 
diff --git a/test/settings.cfg b/test/settings.cfg
index 853c4483..33d9d529 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -198,11 +198,13 @@ pyflakes.ignore stem/client/cell.py => undefined name 'cryptography'
 pyflakes.ignore stem/client/cell.py => undefined name 'hashlib'
 pyflakes.ignore stem/client/datatype.py => redefinition of unused 'pop' from *
 pyflakes.ignore stem/descriptor/__init__.py => undefined name 'cryptography'
+pyflakes.ignore stem/descriptor/certificate.py => undefined name 'cryptography'
 pyflakes.ignore stem/descriptor/hidden_service.py => undefined name 'cryptography'
 pyflakes.ignore stem/interpreter/autocomplete.py => undefined name 'stem'
 pyflakes.ignore stem/interpreter/help.py => undefined name 'stem'
 pyflakes.ignore stem/response/events.py => undefined name 'datetime'
 pyflakes.ignore stem/socket.py => redefinition of unused '_recv'*
+pyflakes.ignore stem/util/__init__.py => undefined name 'cryptography'
 pyflakes.ignore stem/util/conf.py => undefined name 'stem'
 pyflakes.ignore stem/util/enum.py => undefined name 'stem'
 pyflakes.ignore test/require.py => 'cryptography.utils.int_from_bytes' imported but unused
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index f72a92bb..ad6d4950 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -537,7 +537,7 @@ class TestEvents(unittest.TestCase):
     """
 
     import time
-    from stem.control import Controller, EventType
+    from stem.control import EventType
 
     def print_bw(event):
       msg = 'sent: %i, received: %i' % (event.written, event.read)



More information about the tor-commits mailing list