如何自省PEP 484类型提示?

时间:2019-05-20 17:18:27

标签: python-3.x strong-typing

我已经观察到以下功能

 {({ values, error, touched }) => (
        <Form>
          <Field name="Lawn" type="text">
            {({ field, form }) => (
              <Input
                style={form.touched.Lawn && form.errors.Lawn ? 
                                   { style } : { styleError }}
                {...field}
                type="text"
                placeholder="Lawn Details"
              />
            )}
          </Field>

const style = {
  margin: '1em 0em',
  fontSize: '1.5em',
  backgroundColor: 'white',
};

const styleError = {
  margin: '1em 10em',
  fontSize: '1.5em',
};

可以使用表达式def foo(x: int) -> List[int]: return x + 1 获得注释信息,其结果为foo.__annotations__

这是官方API吗?如果不是,是否存在用于获取对象签名的官方API,如果是的话,这是什么?

1 个答案:

答案 0 :(得分:2)

它确实是官方API的一部分。

对于功能,您可能还会看到inspect.signature().

相关问题