Skip to content

Commit c322caa

Browse files
committed
Fix lint issues
* unused-variable: remove variables altogether or name them "_". * unused-import: remove import * consider-using-from-import: Use from-import * Remove version checks for python <=3.3 There are some very minor import order changes: I expect no functionality changes. Fixes #432
1 parent db37ce9 commit c322caa

12 files changed

+21
-85
lines changed

securesystemslib/rsa_keys.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,11 +1069,7 @@ def _decrypt(file_contents, password):
10691069
# specified so that the expected derived key is regenerated correctly.
10701070
# Discard the old "salt" and "iterations" values, as we only need the old
10711071
# derived key.
1072-
(
1073-
junk_old_salt, # pylint: disable=unused-variable
1074-
junk_old_iterations, # pylint: disable=unused-variable
1075-
symmetric_key,
1076-
) = _generate_derived_key(password, salt, iterations)
1072+
_, _, symmetric_key = _generate_derived_key(password, salt, iterations)
10771073

10781074
# Verify the hmac to ensure the ciphertext is valid and has not been altered.
10791075
# See the encryption routine for why we use the encrypt-then-MAC approach.

securesystemslib/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def __init__(self, object_name="object", **required):
748748
"""
749749

750750
# Ensure valid arguments.
751-
for key, schema in required.items(): # pylint: disable=unused-variable
751+
for schema in required.values():
752752
if not isinstance(schema, Schema):
753753
raise exceptions.FormatError(
754754
"Expected Schema but" " got " + repr(schema)

securesystemslib/unittest_toolbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def random_path(self, length=7):
120120
"""Generate a 'random' path consisting of random n-length strings."""
121121

122122
rand_path = "/" + self.random_string(length)
123-
for i in range(2): # pylint: disable=unused-variable
123+
for _ in range(2):
124124
rand_path = os.path.join(rand_path, self.random_string(length))
125125

126126
return rand_path
@@ -130,7 +130,7 @@ def random_string(length=15):
130130
"""Generate a random string of specified length."""
131131

132132
rand_str = ""
133-
for letter in range(length): # pylint: disable=unused-variable
133+
for _ in range(length):
134134
rand_str += random.choice("abcdefABCDEF" + string.digits) # nosec
135135

136136
return rand_str

tests/check_public_interfaces.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,11 @@
2929
when explicitly invoked.
3030
"""
3131

32-
import inspect # pylint: disable=unused-import
33-
import json # pylint: disable=unused-import
3432
import os
3533
import shutil
36-
import sys
3734
import tempfile
3835
import unittest
39-
40-
if sys.version_info >= (3, 3):
41-
import unittest.mock as mock # pylint: disable=consider-using-from-import
42-
else:
43-
import mock
36+
from unittest import mock
4437

4538
import securesystemslib.exceptions # pylint: disable=wrong-import-position
4639
import securesystemslib.gpg.constants # pylint: disable=wrong-import-position

tests/test_ecdsa_keys.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ def test_verify_signature(self):
153153

154154
# Generate an RSA key so that we can verify that non-ECDSA keys are
155155
# rejected.
156-
(
157-
rsa_pem,
158-
junk, # pylint: disable=unused-variable
159-
) = securesystemslib.rsa_keys.generate_rsa_public_and_private()
156+
rsa_pem, _ = securesystemslib.rsa_keys.generate_rsa_public_and_private()
160157

161158
# Verify that a non-ECDSA key (via the PEM argument) is rejected.
162159
self.assertRaises(

tests/test_formats.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ def test_schemas(self):
220220

221221
# Iterate 'valid_schemas', ensuring each 'valid_schema' correctly matches
222222
# its respective 'schema_type'.
223-
for schema_name, ( # pylint: disable=unused-variable
224-
schema_type,
225-
valid_schema,
226-
) in valid_schemas.items():
223+
for (schema_type, valid_schema) in valid_schemas.values():
227224
if not schema_type.matches( # pylint: disable=no-member
228225
valid_schema
229226
):
@@ -237,7 +234,7 @@ def test_schemas(self):
237234
# Test conditions for invalid schemas.
238235
# Set the 'valid_schema' of 'valid_schemas' to an invalid
239236
# value and test that it does not match 'schema_type'.
240-
for schema_name, (schema_type, valid_schema) in valid_schemas.items():
237+
for (schema_type, valid_schema) in valid_schemas.values():
241238
invalid_schema = 0xBAD
242239

243240
if isinstance(schema_type, securesystemslib.schema.Integer):
@@ -251,9 +248,6 @@ def test_schemas(self):
251248

252249
def test_unix_timestamp_to_datetime(self):
253250
# Test conditions for valid arguments.
254-
UNIX_TIMESTAMP_SCHEMA = ( # pylint: disable=invalid-name,unused-variable
255-
securesystemslib.formats.UNIX_TIMESTAMP_SCHEMA
256-
)
257251
self.assertTrue(
258252
datetime.datetime,
259253
securesystemslib.formats.unix_timestamp_to_datetime(499137720),
@@ -377,7 +371,6 @@ def test_encode_canonical(self):
377371
encode = securesystemslib.formats.encode_canonical
378372
result = []
379373
output = result.append
380-
bad_output = 123 # pylint: disable=unused-variable
381374

382375
self.assertEqual('""', encode(""))
383376
self.assertEqual("[1,2,3]", encode([1, 2, 3]))

tests/test_gpg.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,17 @@
2121

2222
import os
2323
import shutil
24-
import sys
2524
import tempfile
2625
import unittest
2726

28-
if sys.version_info >= (3, 3):
29-
from unittest.mock import ( # pylint: disable=no-name-in-module,import-error
30-
patch,
31-
)
32-
else:
33-
from mock import patch # pylint: disable=import-error
34-
3527
# pylint: disable=wrong-import-position
3628
from collections import OrderedDict
3729
from copy import deepcopy
30+
from unittest.mock import patch
3831

39-
import cryptography.hazmat.backends as backends # pylint: disable=consider-using-from-import
4032
import cryptography.hazmat.primitives.hashes as hashing
41-
import cryptography.hazmat.primitives.serialization as serialization # pylint: disable=consider-using-from-import
33+
from cryptography.hazmat import backends
34+
from cryptography.hazmat.primitives import serialization
4235

4336
from securesystemslib import exceptions, process
4437
from securesystemslib.formats import ANY_PUBKEY_DICT_SCHEMA, GPG_PUBKEY_SCHEMA
@@ -62,12 +55,7 @@
6255
have_gpg,
6356
)
6457
from securesystemslib.gpg.dsa import create_pubkey as dsa_create_pubkey
65-
66-
# pylint: disable=unused-import
6758
from securesystemslib.gpg.eddsa import ED25519_SIG_LENGTH
68-
from securesystemslib.gpg.eddsa import create_pubkey as eddsa_create_pubkey
69-
70-
# pylint: enable=unused-import
7159
from securesystemslib.gpg.exceptions import (
7260
CommandError,
7361
KeyExpirationError,

tests/test_hash.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import io
2222
import logging
2323
import os
24-
import sys # pylint: disable=unused-import
2524
import tempfile
2625
import unittest
2726

tests/test_interface.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,16 @@
1717
Unit test for 'interface.py'.
1818
"""
1919

20-
import datetime # pylint: disable=unused-import
21-
import json # pylint: disable=unused-import
2220
import os
2321
import shutil
2422
import stat
25-
import sys
2623
import tempfile
27-
import time # pylint: disable=unused-import
2824
import unittest
25+
from unittest import mock
2926

3027
from cryptography.hazmat.backends import default_backend
3128
from cryptography.hazmat.primitives.serialization import load_pem_private_key
3229

33-
# Use external backport 'mock' on versions under 3.3
34-
if sys.version_info >= (3, 3):
35-
import unittest.mock as mock # pylint: disable=consider-using-from-import
36-
37-
else:
38-
import mock
39-
4030
from securesystemslib import ( # pylint: disable=wrong-import-position
4131
KEY_TYPE_ECDSA,
4232
KEY_TYPE_ED25519,

tests/test_keys.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,30 +175,23 @@ def test_format_metadata_to_key(self):
175175
del test_rsakey_dict["keyid"]
176176

177177
# Call format_metadata_to_key by using the default value for keyid_hash_algorithms
178-
(
179-
rsakey_dict_from_meta_default,
180-
junk, # pylint: disable=unused-variable
181-
) = KEYS.format_metadata_to_key(test_rsakey_dict)
178+
rsakey_formatted, _ = KEYS.format_metadata_to_key(test_rsakey_dict)
182179

183180
# Check if the format of the object returned by calling this function with
184181
# default hash algorithms e.g. securesystemslib.settings.HASH_ALGORITHMS corresponds
185182
# to RSAKEY_SCHEMA format.
186183
self.assertTrue(
187-
securesystemslib.formats.RSAKEY_SCHEMA.matches(
188-
rsakey_dict_from_meta_default
189-
),
184+
securesystemslib.formats.RSAKEY_SCHEMA.matches(rsakey_formatted),
190185
FORMAT_ERROR_MSG,
191186
)
192187

193188
self.assertTrue(
194-
securesystemslib.formats.KEY_SCHEMA.matches(
195-
rsakey_dict_from_meta_default
196-
),
189+
securesystemslib.formats.KEY_SCHEMA.matches(rsakey_formatted),
197190
FORMAT_ERROR_MSG,
198191
)
199192

200193
# Call format_metadata_to_key by using custom value for keyid_hash_algorithms
201-
rsakey_dict_from_meta_custom, junk = KEYS.format_metadata_to_key(
194+
rsakey_dict_from_meta_custom, _ = KEYS.format_metadata_to_key(
202195
test_rsakey_dict, keyid_hash_algorithms=["sha384"]
203196
)
204197

@@ -552,10 +545,7 @@ def test_create_rsa_encrypted_pem(self):
552545
def test_import_rsakey_from_private_pem(self):
553546
# Try to import an rsakey from a valid PEM.
554547
private_pem = self.rsakey_dict["keyval"]["private"]
555-
556-
private_rsakey = KEYS.import_rsakey_from_private_pem( # pylint: disable=unused-variable
557-
private_pem
558-
)
548+
_ = KEYS.import_rsakey_from_private_pem(private_pem)
559549

560550
# Test for invalid arguments.
561551
self.assertRaises(
@@ -681,16 +671,14 @@ def test_import_rsakey_from_pem(self):
681671
def test_import_ecdsakey_from_private_pem(self):
682672
# Try to import an ecdsakey from a valid PEM.
683673
private_pem = self.ecdsakey_dict["keyval"]["private"]
684-
ecdsakey = KEYS.import_ecdsakey_from_private_pem( # pylint: disable=unused-variable
685-
private_pem
686-
)
674+
_ = KEYS.import_ecdsakey_from_private_pem(private_pem)
687675

688676
# Test for an encrypted PEM.
689677
scheme = "ecdsa-sha2-nistp256"
690678
encrypted_pem = securesystemslib.ecdsa_keys.create_ecdsa_encrypted_pem(
691679
private_pem, "password"
692680
)
693-
private_ecdsakey = KEYS.import_ecdsakey_from_private_pem( # pylint: disable=unused-variable
681+
_ = KEYS.import_ecdsakey_from_private_pem(
694682
encrypted_pem.decode("utf-8"), scheme, "password"
695683
)
696684

tests/test_rsa_keys.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,7 @@ def test_decrypt_key(self):
393393
rsa_key, passphrase
394394
)
395395

396-
decrypted_rsa_key = securesystemslib.rsa_keys.decrypt_key( # pylint: disable=unused-variable
397-
encrypted_rsa_key, passphrase
398-
)
396+
_ = securesystemslib.rsa_keys.decrypt_key(encrypted_rsa_key, passphrase)
399397

400398
# Test for invalid arguments.
401399
self.assertRaises(

tests/test_util.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@
1919

2020
import logging
2121
import os
22-
import shutil # pylint: disable=unused-import
2322
import stat
24-
import sys # pylint: disable=unused-import
2523
import tempfile
2624
import timeit
2725
import unittest
2826

29-
import securesystemslib.exceptions as exceptions # pylint: disable=consider-using-from-import
3027
import securesystemslib.hash
3128
import securesystemslib.settings
32-
import securesystemslib.unittest_toolbox as unittest_toolbox # pylint: disable=consider-using-from-import
3329
import securesystemslib.util
30+
from securesystemslib import exceptions, unittest_toolbox
3431

3532
logger = logging.getLogger(__name__)
3633

@@ -135,9 +132,6 @@ def test_B3_get_file_length(self):
135132
filepath = self.make_temp_data_file()
136133

137134
# Computing the length of the tempfile.
138-
digest_object = securesystemslib.hash.digest_filename( # pylint: disable=unused-variable
139-
filepath, algorithm="sha256"
140-
)
141135
file_length = os.path.getsize(filepath)
142136

143137
# Test: Expected input.

0 commit comments

Comments
 (0)