youtype/mypy_boto3_builder

S3 Service resource incorrectly expects Key parameter on some Object methods

Closed this issue · 6 comments

Describe the bug
Since mypy-boto3-builder 7.14.1 (at least), mypy-boto3-s3>=1.26.96 has been expecting a positional argument "Key" in the call to upload_fileobj on the Object class. You can see this in the docs as follows:

# upload_fileobj method definition

def upload_fileobj(
    self,
    Fileobj: Union[IO[Any], StreamingBody],
    Key: str,
    ExtraArgs: Dict[str, Any] = ...,
    Callback: Callable[..., Any] = ...,
    Config: TransferConfig = ...,
) -> None:
    ...

# upload_fileobj method usage example with argument unpacking

kwargs: ObjectUploadFileobjRequestTypeDef = {  # (1)
    "Fileobj": ...,
    "Key": ...,
}

parent.upload_fileobj(**kwargs)

However, the "Key" argument is not required by this resource in boto3, as confirmed by the current AWS boto3 docs.

S3.Object.upload_fileobj(Fileobj, ExtraArgs=None, Callback=None, Config=None)

This issue also appears to affect several other methods of this class, such as upload_file, download_file, download_fileobj, and copy.

This issue does not exist in mypy-boto-s3==1.26.62.

To Reproduce
Steps to reproduce the behavior:

  1. Install boto3-stubs[...]
  2. Run mypy/pyright on the following code sample
import boto3

s3 = boto3.resource("s3")
obj = s3.Object("mybucket", "mykey")
obj.upload_fileobj(open("/tmp/foo"))

Actual output

x.py:5: error: Missing positional argument "Key" in call to "upload_fileobj" of "Object"  [call-arg]
Found 1 error in 1 file (checked 1 source file)

Expected output

Success: no issues found in 1 source file

Additional context
boto3-stubs installation method: pip install boto3-stubs[s3]>=1.26
Python version: 3.10.10

+1, the same spurious Key positional argument to upload_fileobj is currently causing issues in our CI.

If it helps to isolate the issue, there were no problems with the previous environment containing: boto3-stubs==1.26.96 and mypy-boto3-s3==1.26.62.

The problem appeared in my environment with boto3-stubs==1.26.97.post1 and mypy-boto3-s3==1.26.97

vemel commented

Thank you for the report. I will fix it today.

vemel commented

Fixed in mypy-boto3-s3 1.26.97.post2. Please update and let me know if it works as it should.

PS. That was a rookie mistake >_< 4dec4ac

vemel commented

@kgutwin please let me know if the issue is fixed for you.

Thanks for asking! I just switched back to the latest version and can confirm that it is working for me too.