

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 限制
<a name="pipelines-step-decorator-limit"></a>

以下各节概述了在管道步骤中使用 `@step` 装饰器时应注意的限制。

## 函数参数限制
<a name="pipelines-step-decorator-arg"></a>

向 `@step` 装饰函数传递输入参数时，会受到以下限制：
+ 您可以将 `DelayedReturn`、`Properties`（其他类型的步骤）、`Parameter` 和 `ExecutionVariable` 对象作为参数传递给 `@step` 装饰函数。但 `@step` 装饰的函数不支持将 `JsonGet` 和 `Join` 对象作为参数。
+ 您不能通过 `@step` 函数直接访问管道变量。下面的示例会产生一个错误：

  ```
  param = ParameterInteger(name="<parameter-name>", default_value=10)
  
  @step
  def func():
      print(param)
  
  func() # this raises a SerializationError
  ```
+ 您不能将管道变量嵌套到另一个对象中，并将其传递给 `@step` 函数。下面的示例会产生一个错误：

  ```
  param = ParameterInteger(name="<parameter-name>", default_value=10)
  
  @step
  def func(arg):
      print(arg)
  
  func(arg=(param,)) # this raises a SerializationError because param is nested in a tuple
  ```
+ 由于函数的输入和输出是序列化的，因此可以作为函数的输入或输出传递的数据类型受到限制。更多详情，请参阅 [调用远程函数](train-remote-decorator-invocation.md) 中的*数据序列化和反序列化*部分。同样的限制也适用于 `@step` 装饰函数。
+ 任何具有 boto 客户端的对象都不能被序列化，因此不能将此类对象作为 `@step` 装饰函数的输入或输出。例如， SageMaker Python SDK 客户端类（例如`Estimator``Predictor`、和）`Processor`无法序列化。

## 功能导入
<a name="pipelines-step-decorator-best-import"></a>

应在函数内部而不是外部导入步骤所需的库。如果在全局范围内导入，就有可能在序列化函数时发生导入碰撞。例如，`sklearn.pipeline.Pipeline` 可以被 `sagemaker.workflow.pipeline.Pipeline` 覆盖。

## 引用函数返回值的子成员
<a name="pipelines-step-decorator-best-child"></a>

如果引用 `@step` 装饰函数返回值的子成员，则会受到以下限制：
+ 如果 `DelayedReturn` 对象表示元组、列表或 dict，则可以用 `[]` 引用子成员，如下例所示：

  ```
  delayed_return[0]
  delayed_return["a_key"]
  delayed_return[1]["a_key"]
  ```
+ 由于调用函数时无法知道基础元组或列表的确切长度，因此无法解包元组或列表输出。下面的示例会产生一个错误：

  ```
  a, b, c = func() # this raises ValueError
  ```
+ 您不能遍历 `DelayedReturn` 对象。以下示例会引发错误：

  ```
  for item in func(): # this raises a NotImplementedError
  ```
+ 您不能使用“`.`”引用任意子成员。下面的示例会产生一个错误：

  ```
  delayed_return.a_child # raises AttributeError
  ```

## 不支持的现有管道功能
<a name="pipelines-step-decorator-best-unsupported"></a>

您不能使用具有以下管道功能的 `@step` 装饰器：
+ [Pipeline 步骤缓存](https://docs.aws.amazon.com/sagemaker/latest/dg/pipelines-caching.html)
+ [Property 文件](https://docs.aws.amazon.com/sagemaker/latest/dg/build-and-manage-propertyfile.html#build-and-manage-propertyfile-property)