Closed jvtm closed 10 months ago
Thank you for the bug report.
It looks like the only proper solution would be to define your own ServiceName
literal with the services you use:
ServiceName = Literal["ec2", "s3", "sns"]
class AWSAccess:
def __init__(self):
# Some common setup like logging, access rights, etc here.
# This is a stripped down version for pointing out boto3-stubs related bug.
pass
@staticmethod
def client(service: ServiceName, **kwargs):
return boto3.client(service, **kwargs)
@cached_property
def s3(self) -> S3Client:
return self.client("s3")
Or, I can regenerate all packages whenever new services are added or removed.
Let me know what you think.
ServiceName
and ResourceServiceName
up-to-date literals are now included in mypy-boto3
package:
# pip install mypy-boto3
from mypy_boto3.literals import ServiceName, ResourceServiceName
@jvtm I released mypy-boto3 1.28.83.post1
version with this change. Please let me know if you are satisfied with this solution.
Usage example can be found here: https://pypi.org/project/mypy-boto3/
Describe the bug
Issue:
gamespark
client was removed in botocore-1.31.67 / boto3-1.28.67mypy-boto3-xyz
packages include oldServiceName
literal which still includesgamespark
Additionally it looks like that installing a specific version of
boto3-stubs[service]
does not necessarily give the matching or even latest version ofmypy-boto3-service
. It's therefore quite useless to have a line like this in Poetry stylepyproject.toml
:This might leave you with
mypy-boto3-cloudfront
andmypy-boto3-s3
bot being version1.28.0
, while they should perhaps be the latest (at that point in time:mypy-boto3-cloudfront==1.28.36
,mypy-boto3-s3==1.28.55
).But this is not why I created this report, just noticed that it was quite odd, and got me a bit confused while debugging the actual issue.
To Reproduce Steps to reproduce the behavior:
Install
boto3-stubs[s3]
and latestboto3
Run
mypy
on the following code sampleActual output
Expected output
Expected behavior
When
ServiceName
literal has been changed it is updated to each client package.Or alternatively there is a module where the latest one can be imported directly.
Additionally comparing the
ServiceName
literalsAdditional context
ServiceName
Using Poetry for project / virtualenv management, but that is not relevant.