Skip to content

Commit bb4e184

Browse files
committed
bump flake8, fix flake8 and black error
1 parent 95595b8 commit bb4e184

File tree

16 files changed

+1316
-1017
lines changed

16 files changed

+1316
-1017
lines changed

requirements/extras/test_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tox==3.24.5
22
numpy>=1.26.0,<2.0
33
build[virtualenv]==1.2.1
4-
flake8==4.0.1
4+
flake8==7.2.0
55
pytest==6.2.5
66
pytest-cov==3.0.0
77
pytest-rerunfailures==10.2
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
flake8==4.0.1
2-
flake8-future-import==0.4.6
1+
flake8==7.2.0
2+
flake8-future-import==0.4.7

src/sagemaker/config/config_schema.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@ def _simple_path(*args: str):
540540
"minItems": 0,
541541
"maxItems": 50,
542542
},
543-
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html#sagemaker-CreateTrainingJob-request-Environment
543+
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/
544+
# API_CreateTrainingJob.html#sagemaker-CreateTrainingJob-request-Environment
544545
"environmentVariables": {
545546
TYPE: OBJECT,
546547
ADDITIONAL_PROPERTIES: False,
@@ -553,13 +554,15 @@ def _simple_path(*args: str):
553554
},
554555
"maxProperties": 48,
555556
},
556-
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_S3DataSource.html#sagemaker-Type-S3DataSource-S3Uri
557+
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/
558+
# API_S3DataSource.html#sagemaker-Type-S3DataSource-S3Uri
557559
"s3Uri": {
558560
TYPE: "string",
559561
"pattern": "^(https|s3)://([^/]+)/?(.*)$",
560562
"maxLength": 1024,
561563
},
562-
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_AlgorithmSpecification.html#sagemaker-Type-AlgorithmSpecification-ContainerEntrypoint
564+
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/
565+
# API_AlgorithmSpecification.html#sagemaker-Type-AlgorithmSpecification-ContainerEntrypoint
563566
"preExecutionCommand": {TYPE: "string", "pattern": r".*"},
564567
# Regex based on https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_PipelineDefinitionS3Location.html
565568
# except with an additional ^ and $ for the beginning and the end to closer align to
@@ -570,7 +573,8 @@ def _simple_path(*args: str):
570573
"minLength": 3,
571574
"maxLength": 63,
572575
},
573-
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_MonitoringJobDefinition.html#sagemaker-Type-MonitoringJobDefinition-Environment
576+
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/
577+
# API_MonitoringJobDefinition.html#sagemaker-Type-MonitoringJobDefinition-Environment
574578
"environment-Length256-Properties50": {
575579
TYPE: OBJECT,
576580
ADDITIONAL_PROPERTIES: False,
@@ -583,7 +587,8 @@ def _simple_path(*args: str):
583587
},
584588
"maxProperties": 50,
585589
},
586-
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTransformJob.html#sagemaker-CreateTransformJob-request-Environment
590+
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/
591+
# API_CreateTransformJob.html#sagemaker-CreateTransformJob-request-Environment
587592
"environment-Length10240-Properties16": {
588593
TYPE: OBJECT,
589594
ADDITIONAL_PROPERTIES: False,
@@ -596,7 +601,8 @@ def _simple_path(*args: str):
596601
},
597602
"maxProperties": 16,
598603
},
599-
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ContainerDefinition.html#sagemaker-Type-ContainerDefinition-Environment
604+
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/
605+
# API_ContainerDefinition.html#sagemaker-Type-ContainerDefinition-Environment
600606
"environment-Length1024-Properties16": {
601607
TYPE: OBJECT,
602608
ADDITIONAL_PROPERTIES: False,
@@ -609,7 +615,8 @@ def _simple_path(*args: str):
609615
},
610616
"maxProperties": 16,
611617
},
612-
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateProcessingJob.html#sagemaker-CreateProcessingJob-request-Environment
618+
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/
619+
# API_CreateProcessingJob.html#sagemaker-CreateProcessingJob-request-Environment
613620
"environment-Length256-Properties100": {
614621
TYPE: OBJECT,
615622
ADDITIONAL_PROPERTIES: False,
@@ -622,7 +629,8 @@ def _simple_path(*args: str):
622629
},
623630
"maxProperties": 100,
624631
},
625-
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html#sagemaker-CreateTrainingJob-request-Environment
632+
# Regex is taken from https://docs.aws.amazon.com/sagemaker/latest/APIReference/
633+
# API_CreateTrainingJob.html#sagemaker-CreateTrainingJob-request-Environment
626634
"environment-Length512-Properties48": {
627635
TYPE: OBJECT,
628636
ADDITIONAL_PROPERTIES: False,

src/sagemaker/jumpstart/factory/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def get_default_predictor(
104104
"""
105105

106106
# if there's a non-default predictor, do not mutate -- return as is
107-
if type(predictor) != Predictor: # pylint: disable=C0123
107+
if not isinstance(predictor, Predictor):
108108
raise RuntimeError(
109109
"Can only get default predictor from base Predictor class. "
110110
f"Using Predictor class '{type(predictor).__name__}'."

src/sagemaker/local/entities.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,10 +845,10 @@ def _initialize_and_validate_parameters(self, overridden_parameters):
845845
)
846846
raise ClientError(error_msg, "start_pipeline_execution")
847847
parameter_type = default_parameters[param_name].parameter_type
848-
if type(param_value) != parameter_type.python_type: # pylint: disable=C0123
848+
if not isinstance(param_value, parameter_type.python_type):
849849
error_msg = self._construct_validation_exception_message(
850-
"Unexpected type for parameter '{}'. Expected {} but found "
851-
"{}.".format(param_name, parameter_type.python_type, type(param_value))
850+
f"Unexpected type for parameter '{param_name}'. Expected {parameter_type.python_type} \
851+
but found {type(param_value)}."
852852
)
853853
raise ClientError(error_msg, "start_pipeline_execution")
854854
if param_value == "":

src/sagemaker/model_monitor/clarify_model_monitoring.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,9 @@ def __init__(
8686
object that configures network isolation, encryption of
8787
inter-container traffic, security group IDs, and subnets.
8888
"""
89-
if type(self) == __class__: # pylint: disable=unidiomatic-typecheck
89+
if type(self) is __class__:
9090
raise TypeError(
91-
"{} is abstract, please instantiate its subclasses instead.".format(
92-
__class__.__name__
93-
)
91+
f"{__class__.__name__} is abstract, please instantiate its subclasses instead."
9492
)
9593

9694
session = sagemaker_session or Session()

src/sagemaker/serve/model_server/multi_model_server/prepare.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def prepare_for_mms(
8484
image_uri: str,
8585
inference_spec: InferenceSpec = None,
8686
) -> str:
87-
"""Prepares for InferenceSpec using model_path, writes inference.py, and captures dependencies to generate secret_key.
87+
"""Prepares for InferenceSpec using model_path, writes inference.py,
88+
and captures dependencies to generate secret_key.
8889
8990
Args:to
9091
model_path (str) : Argument

tests/integ/sagemaker/jumpstart/private_hub/test_hub_content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_hub_model_reference(setup):
3838

3939
describe_model_response = hub_instance.describe_model(model_name=model_id)
4040
assert describe_model_response is not None
41-
assert type(describe_model_response) == DescribeHubContentResponse
41+
assert isinstance(describe_model_response, DescribeHubContentResponse)
4242
assert describe_model_response.hub_content_name == model_id
4343
assert describe_model_response.hub_content_type == "ModelReference"
4444

tests/integ/sagemaker/serve/test_serve_js_deep_unit_tests.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
def test_js_model_with_optimize_speculative_decoding_config_gated_requests_are_expected(
2525
sagemaker_session,
2626
):
27-
with patch.object(
28-
Session, "create_model", return_value="mock_model"
29-
) as mock_create_model, patch.object(
30-
Session, "endpoint_from_production_variants"
31-
) as mock_endpoint_from_production_variants:
27+
with (
28+
patch.object(Session, "create_model", return_value="mock_model") as mock_create_model,
29+
patch.object(
30+
Session, "endpoint_from_production_variants"
31+
) as mock_endpoint_from_production_variants,
32+
):
3233
iam_client = sagemaker_session.boto_session.client("iam")
3334
role_arn = iam_client.get_role(RoleName=ROLE_NAME)["Role"]["Arn"]
3435

@@ -100,17 +101,18 @@ def test_js_model_with_optimize_speculative_decoding_config_gated_requests_are_e
100101
def test_js_model_with_optimize_sharding_and_resource_requirements_requests_are_expected(
101102
sagemaker_session,
102103
):
103-
with patch.object(
104-
Session,
105-
"wait_for_optimization_job",
106-
return_value={"OptimizationJobName": "mock_optimization_job"},
107-
), patch.object(
108-
Session, "create_model", return_value="mock_model"
109-
) as mock_create_model, patch.object(
110-
Session, "endpoint_from_production_variants", return_value="mock_endpoint_name"
111-
) as mock_endpoint_from_production_variants, patch.object(
112-
Session, "create_inference_component"
113-
) as mock_create_inference_component:
104+
with (
105+
patch.object(
106+
Session,
107+
"wait_for_optimization_job",
108+
return_value={"OptimizationJobName": "mock_optimization_job"},
109+
),
110+
patch.object(Session, "create_model", return_value="mock_model") as mock_create_model,
111+
patch.object(
112+
Session, "endpoint_from_production_variants", return_value="mock_endpoint_name"
113+
) as mock_endpoint_from_production_variants,
114+
patch.object(Session, "create_inference_component") as mock_create_inference_component,
115+
):
114116
iam_client = sagemaker_session.boto_session.client("iam")
115117
role_arn = iam_client.get_role(RoleName=ROLE_NAME)["Role"]["Arn"]
116118

@@ -185,15 +187,17 @@ def test_js_model_with_optimize_sharding_and_resource_requirements_requests_are_
185187
def test_js_model_with_optimize_quantization_on_pre_optimized_model_requests_are_expected(
186188
sagemaker_session,
187189
):
188-
with patch.object(
189-
Session,
190-
"wait_for_optimization_job",
191-
return_value={"OptimizationJobName": "mock_optimization_job"},
192-
), patch.object(
193-
Session, "create_model", return_value="mock_model"
194-
) as mock_create_model, patch.object(
195-
Session, "endpoint_from_production_variants", return_value="mock_endpoint_name"
196-
) as mock_endpoint_from_production_variants:
190+
with (
191+
patch.object(
192+
Session,
193+
"wait_for_optimization_job",
194+
return_value={"OptimizationJobName": "mock_optimization_job"},
195+
),
196+
patch.object(Session, "create_model", return_value="mock_model") as mock_create_model,
197+
patch.object(
198+
Session, "endpoint_from_production_variants", return_value="mock_endpoint_name"
199+
) as mock_endpoint_from_production_variants,
200+
):
197201
iam_client = sagemaker_session.boto_session.client("iam")
198202
role_arn = iam_client.get_role(RoleName=ROLE_NAME)["Role"]["Arn"]
199203

tests/integ/sagemaker/workflow/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def create_and_execute_pipeline(
7070
assert execution_steps[0]["StepStatus"] == step_status
7171
if step_result_type:
7272
result = execution.result(execution_steps[0]["StepName"])
73-
assert (
74-
type(result) == step_result_type
73+
assert isinstance(
74+
result, step_result_type
7575
), f"Expected {step_result_type}, instead found {type(result)}"
7676

7777
if step_result_value:

0 commit comments

Comments
 (0)