Skip to content

Commit 91ac1f3

Browse files
committed
Ignore pylint non-error/fatal pylint issues inline
Inline-disable all non-error/fatal pylint issues raised by running `pylint -j 0 --rcfile=pylintrc securesystemslib tests`, by adding inline comments a la `"# pylint: disable=<issue>[, ...]"`. This allows running pylint on future PRs without spending much effort on existing code, whose future is uncertain (see secure-systems-lab#270). The patch was created mostly automatically with this script: https://gist.github.com/lukpueh/41026a3a7a594164150faf5afce94774 Unfortunately, both black and isort reformat inline comments in a way that pylint won't consider them anymore. Thus, some manual adjustments after running above script were necessary. https://black.readthedocs.io/en/stable/faq.html#why-does-my-linter-or-typechecker-complain-after-i-format-my-code Signed-off-by: Lukas Puehringer <[email protected]>
1 parent b48bc23 commit 91ac1f3

37 files changed

+614
-314
lines changed

securesystemslib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=missing-module-docstring
12
import logging
23

34
# Configure a basic 'securesystemslib' top-level logger with a StreamHandler

securesystemslib/ecdsa_keys.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@
5252
CRYPTO = False
5353

5454
# Perform object format-checking and add ability to handle/raise exceptions.
55-
from securesystemslib import exceptions, formats
55+
from securesystemslib import ( # pylint: disable=wrong-import-position
56+
exceptions,
57+
formats,
58+
)
5659

5760
_SUPPORTED_ECDSA_SCHEMES = ["ecdsa-sha2-nistp256"]
5861

@@ -324,7 +327,9 @@ def verify_signature(public_key, scheme, signature, data):
324327
f"Failed to load PEM key {public_key}"
325328
) from e
326329

327-
if not isinstance(ecdsa_key, ec.EllipticCurvePublicKey):
330+
if not isinstance( # pylint: disable=no-else-raise
331+
ecdsa_key, ec.EllipticCurvePublicKey
332+
):
328333
raise exceptions.FormatError(
329334
"Invalid ECDSA public" " key: " + repr(public_key)
330335
)

securesystemslib/ed25519_keys.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@
7171
except ImportError:
7272
NACL = False
7373

74+
# pylint: disable=wrong-import-position
7475
from securesystemslib import exceptions, formats
7576

7677
# The optimized pure Python implementation of Ed25519. If
7778
# PyNaCl cannot be imported and an attempt to use is made in this module, a
7879
# 'securesystemslib.exceptions.UnsupportedLibraryError' exception is raised.
7980
from securesystemslib._vendor.ed25519 import ed25519 as python_ed25519
8081

82+
# pylint: enable=wrong-import-position
83+
8184
# Supported ed25519 signing schemes: 'ed25519'. The pure Python implementation
8285
# (i.e., ed25519') and PyNaCl (i.e., 'nacl', libsodium + Python bindings)
8386
# modules are currently supported in the creation of 'ed25519' signatures.
@@ -332,7 +335,7 @@ def verify_signature(public_key, scheme, signature, data):
332335

333336
# The pure Python implementation raises 'Exception' if 'signature' is
334337
# invalid.
335-
except Exception:
338+
except Exception: # pylint: disable=broad-except
336339
pass
337340

338341
# This is a defensive check for a valid 'scheme', which should have already

securesystemslib/exceptions.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@
2121
class Error(Exception):
2222
"""Indicate a generic error."""
2323

24-
pass
24+
pass # pylint: disable=unnecessary-pass
2525

2626

27-
class Warning(Warning):
27+
class Warning(Warning): # pylint: disable=redefined-builtin
2828
"""Generic warning. It is used by the 'warnings' module."""
2929

30-
pass
30+
pass # pylint: disable=unnecessary-pass
3131

3232

3333
class FormatError(Error):
3434
"""Indicate an error while validating an object's format."""
3535

36-
pass
36+
pass # pylint: disable=unnecessary-pass
3737

3838

3939
class InvalidMetadataJSONError(FormatError):
4040
"""Indicate that a metadata file is not valid JSON."""
4141

42-
def __init__(self, exception):
42+
def __init__(self, exception): # pylint: disable=super-init-not-called
4343
# Store the original exception.
4444
self.exception = exception
4545

@@ -51,13 +51,15 @@ def __str__(self):
5151
class UnsupportedAlgorithmError(Error):
5252
"""Indicate an error while trying to identify a user-specified algorithm."""
5353

54-
pass
54+
pass # pylint: disable=unnecessary-pass
5555

5656

5757
class BadHashError(Error):
5858
"""Indicate an error while checking the value a hash object."""
5959

60-
def __init__(self, expected_hash, observed_hash):
60+
def __init__(
61+
self, expected_hash, observed_hash
62+
): # pylint: disable=super-init-not-called
6163
self.expected_hash = expected_hash
6264
self.observed_hash = observed_hash
6365

@@ -74,19 +76,21 @@ def __str__(self):
7476
class BadPasswordError(Error):
7577
"""Indicate an error after encountering an invalid password."""
7678

77-
pass
79+
pass # pylint: disable=unnecessary-pass
7880

7981

8082
class CryptoError(Error):
8183
"""Indicate any cryptography-related errors."""
8284

83-
pass
85+
pass # pylint: disable=unnecessary-pass
8486

8587

8688
class BadSignatureError(CryptoError):
8789
"""Indicate that some metadata has a bad signature."""
8890

89-
def __init__(self, metadata_role_name):
91+
def __init__(
92+
self, metadata_role_name
93+
): # pylint: disable=super-init-not-called
9094
self.metadata_role_name = metadata_role_name
9195

9296
def __str__(self):
@@ -96,41 +100,41 @@ def __str__(self):
96100
class UnknownMethodError(CryptoError):
97101
"""Indicate that a user-specified cryptograpthic method is unknown."""
98102

99-
pass
103+
pass # pylint: disable=unnecessary-pass
100104

101105

102106
class UnsupportedLibraryError(Error):
103107
"""Indicate that a supported library could not be located or imported."""
104108

105-
pass
109+
pass # pylint: disable=unnecessary-pass
106110

107111

108112
class InvalidNameError(Error):
109113
"""Indicate an error while trying to validate any type of named object."""
110114

111-
pass
115+
pass # pylint: disable=unnecessary-pass
112116

113117

114118
class NotFoundError(Error):
115119
"""If a required configuration or resource is not found."""
116120

117-
pass
121+
pass # pylint: disable=unnecessary-pass
118122

119123

120124
class URLMatchesNoPatternError(Error):
121125
"""If a URL does not match a user-specified regular expression."""
122126

123-
pass
127+
pass # pylint: disable=unnecessary-pass
124128

125129

126130
class InvalidConfigurationError(Error):
127131
"""If a configuration object does not match the expected format."""
128132

129-
pass
133+
pass # pylint: disable=unnecessary-pass
130134

131135

132136
class StorageError(Error):
133137
"""Indicate an error occured during interaction with an abstracted storage
134138
backend."""
135139

136-
pass
140+
pass # pylint: disable=unnecessary-pass

securesystemslib/formats.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def _create_gpg_pubkey_with_subkey_schema(pubkey_schema):
334334
# define the attributes of the object in its `_required` property, even if
335335
# such a schema is of type `Optional`.
336336
# TODO: Find a way that does not require to access a protected member
337-
schema._required.append(
337+
schema._required.append( # pylint: disable=protected-access
338338
subkey_schema_tuple
339339
) # pylint: disable=protected-access
340340
return schema
@@ -640,7 +640,9 @@ def _canonical_string_encoder(string):
640640
return string
641641

642642

643-
def _encode_canonical(object, output_function):
643+
def _encode_canonical(
644+
object, output_function
645+
): # pylint: disable=missing-function-docstring,redefined-builtin
644646
# Helper for encode_canonical. Older versions of json.encoder don't
645647
# even let us replace the separators.
646648

@@ -680,7 +682,9 @@ def _encode_canonical(object, output_function):
680682
raise exceptions.FormatError("I cannot encode " + repr(object))
681683

682684

683-
def encode_canonical(object, output_function=None):
685+
def encode_canonical( # pylint: disable=inconsistent-return-statements
686+
object, output_function=None # pylint: disable=redefined-builtin
687+
):
684688
"""
685689
<Purpose>
686690
Encode 'object' in canonical JSON form, as specified at

0 commit comments

Comments
 (0)