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
518 stars 35 forks source link

Incorrectly typed `aioboto.dynamodb.BatchWriter` #204

Closed YaraslauZhylko closed 11 months ago

YaraslauZhylko commented 1 year ago

Describe the bug

aioboto3.dynamodb.BatchWriter might be incorrectly typed.

To Reproduce Steps to reproduce the behavior:

  1. Use fully correct and working aioboto3 code suggested by aioboto3 docs:

    import aioboto3
    
    session = aioboto3.Session()
    async with session.resource("dynamodb") as resource:
        table = await resource.Table("SomeTable")
        async with table.batch_writer() as batch:
            await batch.delete_item(Key={"id": "123"})
            await batch.delete_item(Key={"id": "456"})
  2. Run mypy.

  3. Get an error.

Actual output

  test.py:6: error: "Coroutine[Any, Any, Any]" has no attribute "__aenter__"  [attr-defined]
  test.py:6: error: "Coroutine[Any, Any, Any]" has no attribute "__aexit__"  [attr-defined]

Expected output

No errors.

Additional context

vemel commented 1 year ago

Thank you for the report!

I added a fix for this. Now Table is inherited from aioboto3.dynamodb.table.CustomTableResource, which is annotated in types-aioboto3 package. I will release a fix today.

vemel commented 1 year ago

Fixed in mypy_boto3_builder 7.14.8. Please test and let me know if it works as it should.

I released a new version of types-aiobotocore-dynamodb 2.5.0.post2 with the hotfix.

YaraslauZhylko commented 1 year ago

This particular error is fixed.

But there seems to be some new issues: Module "types_aiobotocore_dynamodb.type_defs" has no attribute "UpdateItemOutputTableTypeDef"; maybe "UpdateItemOutputOutputTypeDef"? [attr-defined]

The error is caused by this import:

from types_aiobotocore_dynamodb.type_defs import UpdateItemOutputTableTypeDef

That was not the case in 2.5.0.post1 or 2.5.2. There was no error importing UpdateItemOutputTableTypeDef.

vemel commented 1 year ago

Yes, this is due to the new naming introduced in 7.14.7. All output shapes now have OutputTypeDef postfix to differentiate them from input shapes. The issue was that some shapes are used both as input (not all keys are required) and as output (all keys are present). To avoid a name clash, I added OutputTypeDef postfix, even if the underlying shape itself has Output in the shape name.

Please update your code, the correct name is UpdateItemOutputOutputTypeDef now.

YaraslauZhylko commented 1 year ago

It does seem to work correctly with the new naming in 2.5.0.post2. Thanks for fixing it.

Should we expect the fixed to be released in 2.5.3 any time soon?

vemel commented 1 year ago

@YaraslauZhylko yes, I am going to update 2.5.2 as well. No rename required, I am working on a new update that will be compatible with pre-7.14.7 TypeDef name generation.

vemel commented 1 year ago

@YaraslauZhylko just released types-aiobotocore-dynamodb 2.5.0.post3. Please test it and let me know if it works as it should.

Also, there is types-aiobotocore-dynamodb 2.5.2.post1 with the fix included.

YaraslauZhylko commented 1 year ago

@vemel 2.5.0.post3 and 2.5.2.post1 work without renaming. :+1:

YaraslauZhylko commented 1 year ago

Will there by any other updates today (like 2.5.3) or should I stay with 2.5.2.post1 for now?

vemel commented 1 year ago

@YaraslauZhylko aiobotocore 2.5.3 has not been released yet. types-aiobotocore version is always the same as the corresponding aiobotocore version, plus post releases in case of urgent fixes.

So, 2.5.2.post1 is the latest, no more updates for today.

Feel free to close the issue if it is resolved.