Python 定义AWS Boto3类型的显式返回
如何将Python 定义AWS Boto3类型的显式返回,python,amazon-web-services,types,boto3,Python,Amazon Web Services,Types,Boto3,如何将对象替换为正确的返回类型boto3.resources.factory.ec2.Instance?这是为了智能感知的目的 # Note: self._resource -> boto3.resource(...) def instance(self, instance_id: str) -> object: """ Gets EC2 instance based on Instance ID. :param instance_id: AWS EC2 I
对象
替换为正确的返回类型boto3.resources.factory.ec2.Instance
?这是为了智能感知的目的
# Note: self._resource -> boto3.resource(...)
def instance(self, instance_id: str) -> object:
"""
Gets EC2 instance based on Instance ID.
:param instance_id: AWS EC2 Instance ID
"""
instance = self._resource.Instance(instance_id)
return instance
根据类型(ec2.instance('i-123456'))
(ec2
在本例中是包含instance()
方法的类的实例),它返回
。但是,boto3使用工厂模式返回instance
类的实例;它隐藏了实例
类的定义位置。。大多数IDE都会很聪明地接受这一点
def instance(self, instance_id: str):
"""
Gets EC2 instance based on Instance ID.
:param instance_id: AWS EC2 Instance ID
:rtype: boto3.resources.factory.ec2.Instance
"""
instance = self._resource.Instance(instance_id)
return instance
from typing import TypeVar
T = TypeVar('T', bound='boto3.resources.factory.ec2.Instance')