小编Log*_*mon的帖子

我正在尝试在 boto3 周围输入注释,但模块“botocore.client”没有属性“EC2”

我正在围绕 boto3 编写自己的包装器,以实现快速触发功能。

我正在尝试输入注释boto3.session().client('ec2')返回的内容。

调试器说它是<class 'botocore.client.EC2'>,但如果我这样写下来,python 会因运行时错误而崩溃

ec2: botocore.client.EC2
AttributeError: module 'botocore.client' has no attribute 'EC2'
Run Code Online (Sandbox Code Playgroud)

删除类型注释适用于运行时,但它使 linting 非常有限。

有没有一种相当快速的方法或技巧来使用这个 boto3 案例进行打字?

我正在谈论的代码如下:

class AWS_Client:
    # debugger says it's <class 'botocore.client.EC2'>,
    # but mypy says this class does not exist
    ec2: botocore.client.EC2
    asg: botocore.client.AutoScaling
    region: str
    instance_id: str

    def __init__(self,
                 profile_name: Optional[str] = None,
                 instance_id: str = '',
                 region_name: str = '',
                 **kwargs) -> None:
        global config

        self.instance_id = instance_id or ec2_meta('instance-id').text
        self.region = region_name or …
Run Code Online (Sandbox Code Playgroud)

python boto3 python-typing

3
推荐指数
1
解决办法
3106
查看次数

标签 统计

boto3 ×1

python ×1

python-typing ×1