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

Missing `total=False` on some TypedDict with boto3-stubs>=1.28.3 #205

Closed Wurstnase closed 1 year ago

Wurstnase commented 1 year ago

Describe the bug Some TypeDicts are not total=False anymore. With mypy-boto3-secretsmanger==1.28.3 the flag is gone in the TypeDef.

To Reproduce Steps to reproduce the behavior:

  1. Install mypy-boto3-secretsmanger==1.28.3
  2. Run mypy/pyright on the following code sample
from mypy_boto3_secretsmanger.type_defs import RotationRulesTypeTypeDef

rules: RotationRulesTypeTypeDef = {"AutomaticallyAfterDays": 365}
...

Actual output

error: Missing keys ("Duration", "ScheduleExpression") for TypedDict "RotationRulesTypeTypeDef"  [typeddict-item]

Expected output

no error
DominikVollandTNG commented 1 year ago

Same issue seen with S3 for multiple TypedDicts, specifically CORSRuleTypeDef, ServerSideEncryptionByDefaultTypeDef, ServerSideEncryptionRuleTypeDef, LifecycleRuleTypeDef, LoggingEnabledTypeDef, TopicConfigurationTypeDef, MetricsConfigurationTypeDef.

vemel commented 1 year ago

Thank you for the report!

Looks like the issue is related to a new logic for marking output TypedDict shapes as total. However, some shapes are used both as input and output. The proper fix would be to generate two TypedDicts (e.g. RotationRulesTypeTypeDef and RotationRulesTypeOutputTypeDef).

I will take a look.

vemel commented 1 year ago

Fixed in mypy_boto3_builder 7.14.7 release. Please let me know if it works as it should.

All output TypeDefs now have postfix OutputTypeDef. The corresponding input TypeDef uses totality from the underlying Shape. OutputTypeDef is always total=True. If you use type annotations explicitly in your code, some rewrite may be required: change ...TypeDef to ...OutputTypeDef if it no longer exists.

I also published new packages with the hotfix included:

ecs-jnguyen commented 1 year ago

@vemel

If you guys are pushing breaking changes like this could we yank it and increment the major version please?

The post1 is a breaking change for us. I started getting this error after the post1 version has been pushed.

    from mypy_boto3_ec2.type_defs import SubnetTypeDef
ImportError: cannot import name 'SubnetTypeDef' from 'mypy_boto3_ec2.type_defs'
vemel commented 1 year ago

@ecs-jnguyen Makes sense. I came up with a non-conflicting solution. I will release it in a few hours. Also, I am going to release post2 to affected packages.

vemel commented 1 year ago

@ecs-jnguyen Just released mypy-boto3-ec2 1.28.3.post2 with the fix included. Please test it and let me know if it works as it should.

Also, many other packages were updated, check 7.15.0 release notes.

Wurstnase commented 1 year ago

LGTM. Thanks for your fast response and fixes.