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

Support configuration of `typing` vs `typing_extensions` #221

Closed tobni closed 1 year ago

tobni commented 1 year ago

Describe your idea I would like to enforce the library to use typing_extensions, regardless of my interpreter version. The top level if clause in the stub files could maybe support some type of configuration, like an environment variable? Code sample

if sys.version_info >= (3, 9) or not os.environ.get("BOTO_STUBS_USE_TYPING_EXTENSIONS"):
    from typing import TypedDict
else:
    from typing_extensions import TypedDict

Additional context pydantic v2 requires TypedDict to be typing_extensions.TypedDict unless python is version 3.12 or higher. I cannot upgrade to this version of python, but I do want pydantics TypedDict support for parsing your generated TypedDicts.

vemel commented 1 year ago

Hello,

Thank you for the feature request. It makes sense. However, env variables are not supported in *.pyi files, so it will not work. The solution could be to use typing_extensions if available, and fallback to typing. Another solution would be always to use typing_extensions and make it a mandatory dependency.

I will check pydantic docs.

tobni commented 1 year ago

https://docs.pydantic.dev/2.3/errors/usage_errors/#typed-dict-version is the cause for my request.

vemel commented 1 year ago

I just released mypy_boto3_builder 7.18.0 with new import logic. I am going to generate all packages later today.

vemel commented 1 year ago

@tobni I released all boto3-stubs packages built with the new builder version. Please test and let me know if it works as it should.