object
を返品タイプboto3.resources.factory.ec2.Instance
に置き換えるにはどうすればよいですか?それはインテリセンスの目的のためです。AWS Boto3タイプの明示的返品の定義
# 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
type(ec2.instance('i-123456'))
によれば、(この例では、ec2
instance()
メソッドを含むクラスのインスタンスである)、それは<class 'boto3.resources.factory.ec2.Instance'>
を返します。ただし、boto3はファクトリパターンを使用してInstance
クラスのインスタンスを返します。これはInstance
クラスの定義の場所を隠しています。