Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Enable more pylint rules and fixes pylint issues #2544

Merged
merged 4 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ disable=
W0613, # Unused argument %r
W0640, # Cell variable %s defined in loop A variable used in a closure is defined in a loop
R0902, # Too many instance attributes (%s/%s)
R0903, # Too few public methods (%s/%s)
# R0903, # Too few public methods (%s/%s)
R0913, # Too many arguments (%s/%s)
W0703, # Catching too general exception %s
R0904, # Too many public methods (%s/%s)
Expand Down Expand Up @@ -98,9 +98,9 @@ disable=
C0103, # Class constant name "%s" doesn't conform to UPPER_CASE naming style ('([^\\W\\da-z][^\\Wa-z]*|__.*__)$' pattern) (invalid-name)
# New recommendations, disable for now to avoid introducing behaviour changes.
R1729, # Use a generator instead '%s' (use-a-generator)
R1732, # Consider using 'with' for resource-allocating operations (consider-using-with)
# R1732, # Consider using 'with' for resource-allocating operations (consider-using-with)
# This applies to CPython only.
I1101, # Module 'math' has no 'pow' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member)
# I1101, # Module 'math' has no 'pow' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member)
# Added to allow linting. Need to work on removing over time
R0801, # dupilcated code
R0401, # Cyclic import
Expand All @@ -115,7 +115,7 @@ disable=
E1101, # No member
W0622, # Redefining built-in 'property' (redefined-builtin)
# W0611, # unused imports
W0231, # super not called
# W0231, # super not called
W0212, # protected-access
W0201, # attribute-defined-outside-init
R1725, # Consider using Python 3 style super() without arguments (super-with-arguments)
Expand All @@ -126,8 +126,8 @@ disable=
W0223, # abstract-method
W0107, # unnecessary-pass
W0707, # raise-missing-from
R1720, # no-else-raise
W0621, # redefined-outer-name
# R1720, # no-else-raise
# W0621, # redefined-outer-name
E0203, # access-member-before-definition
W0221, # arguments-differ
R1710, # inconsistent-return-statements
Expand All @@ -136,23 +136,23 @@ disable=
W0105, # String statement has no effect (pointless-string-statement)
C0206, # Consider iterating with .items() (consider-using-dict-items)
W9008, # Redundant returns documentation (redundant-returns-doc)
E0602, # undefined-variable
# E0602, # undefined-variable
C0112, # empty-docstring
C0116, # missing-function-docstring
# C0200, # consider-using-enumerate
# R5501, # Consider using "elif" instead of "else if" (else-if-used)
W9017, # differing-param-doc
W9018, # differing-type-doc
W0511, # fixme
C0325, # superfluous-parens
R1701, # consider-merging-isinstance
# C0325, # superfluous-parens
# R1701, # consider-merging-isinstance
C0302, # too-many-lines
C0303, # trailing-whitespace
R1721, # unnecessary-comprehension
C0121, # singleton-comparison
E1305, # too-many-format-args
R1724, # no-else-continue
E0611, # no-name-in-module
# R1721, # unnecessary-comprehension
# C0121, # singleton-comparison
# E1305, # too-many-format-args
# R1724, # no-else-continue
# E0611, # no-name-in-module
W9013, # missing-yield-doc
W9014, # missing-yield-type-doc
C0201, # consider-iterating-dictionary
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ def _add_gateway_responses(self):
"Unable to set GatewayResponses attribute because "
"intrinsic functions are not supported for this field.",
)
elif not isinstance(responses_value, dict):
if not isinstance(responses_value, dict):
raise InvalidResourceException(
self.logical_id,
"Invalid property type '{}' for GatewayResponses. "
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/model/api/http_api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def _add_tags(self):
self.logical_id,
"Unable to add `Tags` because 'DefinitionBody' does not contain a valid OpenApi definition.",
)
elif not OpenApiEditor.is_valid(self.definition_body):
if not OpenApiEditor.is_valid(self.definition_body):
return

if not self.tags:
Expand Down
8 changes: 4 additions & 4 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def _validate_dlq(self):
"'DeadLetterQueue' requires Type and TargetArn properties to be specified.",
)

if not (isinstance(self.DeadLetterQueue.get("Type"), str)):
if not isinstance(self.DeadLetterQueue.get("Type"), str):
raise InvalidResourceException(
self.logical_id,
"'DeadLetterQueue' property 'Type' should be of type str.",
Expand Down Expand Up @@ -733,16 +733,16 @@ def _construct_inline_code(*args, **kwargs):
"ImageUri": construct_image_code_object,
}

filtered_artifacts = dict(filter(lambda x: x[1] != None, artifacts.items()))
filtered_artifacts = dict(filter(lambda x: x[1] is not None, artifacts.items()))
# There are more than one allowed artifact types present, raise an Error.
# There are no valid artifact types present, also raise an Error.
if len(filtered_artifacts) > 1 or len(filtered_artifacts) == 0:
if packagetype == ZIP and len(filtered_artifacts) == 0:
raise InvalidResourceException(self.logical_id, "Only one of 'InlineCode' or 'CodeUri' can be set.")
elif packagetype == IMAGE:
if packagetype == IMAGE:
raise InvalidResourceException(self.logical_id, "'ImageUri' must be set.")

filtered_keys = [key for key in filtered_artifacts.keys()]
filtered_keys = list(filtered_artifacts.keys())
# NOTE(sriram-mv): This precedence order is important. It is protect against python2 vs python3
# dictionary ordering when getting the key values with .keys() on a dictionary.
# Do not change this precedence order.
Expand Down
4 changes: 2 additions & 2 deletions samtranslator/model/stepfunctions/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def to_cloudformation(self):
raise InvalidResourceException(
self.logical_id, "Specify either 'Definition' or 'DefinitionUri' property and not both."
)
elif self.definition:
if self.definition:
processed_definition = deepcopy(self.definition)
substitutions = self._replace_dynamic_values_with_substitutions(processed_definition)
if len(substitutions) > 0:
Expand All @@ -132,7 +132,7 @@ def to_cloudformation(self):
raise InvalidResourceException(
self.logical_id, "Specify either 'Role' or 'Policies' property and not both."
)
elif self.role:
if self.role:
self.state_machine.RoleArn = self.role
elif self.policies:
if not self.managed_policy_map:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def _make_service_call_with_retry(self, service_call, app_id, semver, key, logic
sleep(sleep_time)
self._total_wait_time += sleep_time
continue
else:
raise e
raise e
call_succeeded = True
break
if not call_succeeded:
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def replace_recursively(bmt):
return to_return
if isinstance(bmt, list):
return [replace_recursively(item) for item in bmt]
if isinstance(bmt, str) or isinstance(bmt, Py27UniStr):
if isinstance(bmt, (Py27UniStr, str)):
return Py27UniStr(bmt.replace("~1", "/"))
return bmt

Expand Down
2 changes: 1 addition & 1 deletion samtranslator/translator/logical_id_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_hash(self, length=HASH_LENGTH):
encoded_data_str = self.data_str
if sys.version_info.major == 2:
# In Py2, only unicode needs to be encoded.
if isinstance(self.data_str, unicode):
if isinstance(self.data_str, unicode): # pylint: disable=E0602
encoded_data_str = self.data_str.encode("utf-8")
else:
# data_str should always be unicode on python 3
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/translator/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _get_resources_to_iterate(self, sam_template, macro_resolver):
# Skip over the resource if it is not a SAM defined Resource
if not macro_resolver.can_resolve(resource):
continue
elif resource["Type"] == "AWS::Serverless::Function":
if resource["Type"] == "AWS::Serverless::Function":
functions.append(data)
elif resource["Type"] == "AWS::Serverless::StateMachine":
statemachines.append(data)
Expand Down