Skip to content

Commit 01ed740

Browse files
authored
change: enable inconsistent-return-statements Pylint check (#930)
Note that this commit also raises ValueErrors in situations that would previously have returned None. Per PEP8: Be consistent in return statements. Either all return statements in a function should return an expression, or none of them should. If any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None, and an explicit return statement should be present at the end of the function (if reachable).
1 parent 2cf69b2 commit 01ed740

File tree

7 files changed

+24
-4
lines changed

7 files changed

+24
-4
lines changed

.pylintrc

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ disable=
9191
useless-object-inheritance, # TODO: Remove unnecessary imports
9292
cyclic-import, # TODO: Resolve cyclic imports
9393
no-self-use, # TODO: Convert methods to functions where appropriate
94-
inconsistent-return-statements, # TODO: Make returns consistent
9594
consider-merging-isinstance, # TODO: Merge isinstance where appropriate
9695
consider-using-in, # TODO: Consider merging comparisons with "in"
9796
too-many-public-methods, # TODO: Resolve

src/sagemaker/job.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def _prepare_channel(
169169
input_mode=None,
170170
):
171171
if not channel_uri:
172-
return
172+
return None
173173
if not channel_name:
174174
raise ValueError(
175175
"Expected a channel name if a channel URI {} is specified".format(channel_uri)

src/sagemaker/local/data.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,21 @@ def get_data_source_instance(data_source, sagemaker_session):
3838
sagemaker_session (:class:`sagemaker.session.Session`): a SageMaker Session to interact with
3939
S3 if required.
4040
41-
Returns
41+
Returns:
4242
:class:`sagemaker.local.data.DataSource`: an Instance of a Data Source
4343
44+
Raises:
45+
ValueError: If parsed_uri scheme is neither `file` nor `s3`, raise an error.
46+
4447
"""
4548
parsed_uri = urlparse(data_source)
4649
if parsed_uri.scheme == "file":
4750
return LocalFileDataSource(parsed_uri.netloc + parsed_uri.path)
4851
if parsed_uri.scheme == "s3":
4952
return S3DataSource(parsed_uri.netloc, parsed_uri.path, sagemaker_session)
53+
raise ValueError(
54+
"data_source must be either file or s3. parsed_uri.scheme: {}".format(parsed_uri.scheme)
55+
)
5056

5157

5258
def get_splitter_instance(split_type):

src/sagemaker/model.py

+1
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ def deploy(
389389

390390
if self.predictor_cls:
391391
return self.predictor_cls(self.endpoint_name, self.sagemaker_session)
392+
return None
392393

393394
def transformer(
394395
self,

src/sagemaker/pipeline.py

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def deploy(
115115
)
116116
if self.predictor_cls:
117117
return self.predictor_cls(self.endpoint_name, self.sagemaker_session)
118+
return None
118119

119120
def _create_sagemaker_pipeline_model(self, instance_type):
120121
"""Create a SageMaker Model Entity

src/sagemaker/predictor.py

+5
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ def __call__(self, stream, content_type=CONTENT_TYPE_NPY):
392392
return np.load(BytesIO(stream.read()))
393393
finally:
394394
stream.close()
395+
raise ValueError(
396+
"content_type must be one of the following: CSV, JSON, NPY. content_type: {}".format(
397+
content_type
398+
)
399+
)
395400

396401

397402
numpy_deserializer = _NumpyDeserializer()

src/sagemaker/rl/estimator.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ def create_model(
184184
MXNet was used as RL backend;
185185
* sagemaker.tensorflow.serving.Model - if image_name wasn't specified and
186186
TensorFlow was used as RL backend.
187-
187+
Raises:
188+
ValueError: If image_name was not specified and framework enum is not valid.
188189
"""
189190
base_args = dict(
190191
model_data=self.model_data,
@@ -230,6 +231,9 @@ def create_model(
230231
return MXNetModel(
231232
framework_version=self.framework_version, py_version=PYTHON_VERSION, **extended_args
232233
)
234+
raise ValueError(
235+
"An unknown RLFramework enum was passed in. framework: {}".format(self.framework)
236+
)
233237

234238
def train_image(self):
235239
"""Return the Docker image to use for training.
@@ -399,6 +403,9 @@ def default_metric_definitions(cls, toolkit):
399403
400404
Returns:
401405
list: metric definitions
406+
407+
Raises:
408+
ValueError: If toolkit enum is not valid.
402409
"""
403410
if toolkit is RLToolkit.COACH:
404411
return [
@@ -412,3 +419,4 @@ def default_metric_definitions(cls, toolkit):
412419
{"Name": "episode_reward_mean", "Regex": "episode_reward_mean: (%s)" % float_regex},
413420
{"Name": "episode_reward_max", "Regex": "episode_reward_max: (%s)" % float_regex},
414421
]
422+
raise ValueError("An unknown RLToolkit enum was passed in. toolkit: {}".format(toolkit))

0 commit comments

Comments
 (0)