youtype / mypy_boto3_builder

Type annotations builder for boto3 compatible with VSCode, PyCharm, Emacs, Sublime Text, pyright and mypy.
https://youtype.github.io/mypy_boto3_builder/
MIT License
544 stars 36 forks source link

S3 Service resource incorrectly expects Key parameter on some Object methods #193

Closed kgutwin closed 1 year ago

kgutwin commented 1 year ago

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

masalim2 commented 1 year ago

+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 1 year ago

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

vemel commented 1 year ago

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 >_< https://github.com/youtype/mypy_boto3_builder/commit/4dec4ac206c990fa968fc418b10f152839ddcdaf

masalim2 commented 1 year ago

Thank you so much for the fast attention, it’s much appreciated! Confirmed that it fixed the issue for me.

On Thu, Mar 23, 2023 at 11:50 AM Vlad Emelianov @.***> wrote:

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 https://github.com/youtype/mypy_boto3_builder/commit/4dec4ac206c990fa968fc418b10f152839ddcdaf

— Reply to this email directly, view it on GitHub https://github.com/youtype/mypy_boto3_builder/issues/193#issuecomment-1481537800, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE753UY3AMMA2XXFGAIQLDTW5R5NBANCNFSM6AAAAAAWFGYFPE . You are receiving this because you commented.Message ID: @.***>

vemel commented 1 year ago

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

kgutwin commented 1 year ago

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