Skip to content

Commit

Permalink
Ignore pylint non-error/fatal pylint issues inline
Browse files Browse the repository at this point in the history
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 #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 <lukas.puehringer@nyu.edu>
  • Loading branch information
lukpueh committed Oct 20, 2022
1 parent b48bc23 commit 91ac1f3
Show file tree
Hide file tree
Showing 37 changed files with 614 additions and 314 deletions.
1 change: 1 addition & 0 deletions securesystemslib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-module-docstring
import logging

# Configure a basic 'securesystemslib' top-level logger with a StreamHandler
Expand Down
9 changes: 7 additions & 2 deletions securesystemslib/ecdsa_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
CRYPTO = False

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

_SUPPORTED_ECDSA_SCHEMES = ["ecdsa-sha2-nistp256"]

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

if not isinstance(ecdsa_key, ec.EllipticCurvePublicKey):
if not isinstance( # pylint: disable=no-else-raise
ecdsa_key, ec.EllipticCurvePublicKey
):
raise exceptions.FormatError(
"Invalid ECDSA public" " key: " + repr(public_key)
)
Expand Down
5 changes: 4 additions & 1 deletion securesystemslib/ed25519_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@
except ImportError:
NACL = False

# pylint: disable=wrong-import-position
from securesystemslib import exceptions, formats

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

# pylint: enable=wrong-import-position

# Supported ed25519 signing schemes: 'ed25519'. The pure Python implementation
# (i.e., ed25519') and PyNaCl (i.e., 'nacl', libsodium + Python bindings)
# modules are currently supported in the creation of 'ed25519' signatures.
Expand Down Expand Up @@ -332,7 +335,7 @@ def verify_signature(public_key, scheme, signature, data):

# The pure Python implementation raises 'Exception' if 'signature' is
# invalid.
except Exception:
except Exception: # pylint: disable=broad-except
pass

# This is a defensive check for a valid 'scheme', which should have already
Expand Down
38 changes: 21 additions & 17 deletions securesystemslib/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@
class Error(Exception):
"""Indicate a generic error."""

pass
pass # pylint: disable=unnecessary-pass


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

pass
pass # pylint: disable=unnecessary-pass


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

pass
pass # pylint: disable=unnecessary-pass


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

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

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

pass
pass # pylint: disable=unnecessary-pass


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

def __init__(self, expected_hash, observed_hash):
def __init__(
self, expected_hash, observed_hash
): # pylint: disable=super-init-not-called
self.expected_hash = expected_hash
self.observed_hash = observed_hash

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

pass
pass # pylint: disable=unnecessary-pass


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

pass
pass # pylint: disable=unnecessary-pass


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

def __init__(self, metadata_role_name):
def __init__(
self, metadata_role_name
): # pylint: disable=super-init-not-called
self.metadata_role_name = metadata_role_name

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

pass
pass # pylint: disable=unnecessary-pass


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

pass
pass # pylint: disable=unnecessary-pass


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

pass
pass # pylint: disable=unnecessary-pass


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

pass
pass # pylint: disable=unnecessary-pass


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

pass
pass # pylint: disable=unnecessary-pass


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

pass
pass # pylint: disable=unnecessary-pass


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

pass
pass # pylint: disable=unnecessary-pass
10 changes: 7 additions & 3 deletions securesystemslib/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _create_gpg_pubkey_with_subkey_schema(pubkey_schema):
# define the attributes of the object in its `_required` property, even if
# such a schema is of type `Optional`.
# TODO: Find a way that does not require to access a protected member
schema._required.append(
schema._required.append( # pylint: disable=protected-access
subkey_schema_tuple
) # pylint: disable=protected-access
return schema
Expand Down Expand Up @@ -640,7 +640,9 @@ def _canonical_string_encoder(string):
return string


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

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


def encode_canonical(object, output_function=None):
def encode_canonical( # pylint: disable=inconsistent-return-statements
object, output_function=None # pylint: disable=redefined-builtin
):
"""
<Purpose>
Encode 'object' in canonical JSON form, as specified at
Expand Down
Loading

0 comments on commit 91ac1f3

Please sign in to comment.