Closed Wurstnase closed 10 months ago
Hello!
Session.get_credentials
can return None
if there are no credential providers, or none of the providers return valid credentials. So, you have to check if creds are not None
import boto3
session = boto3.Session()
creds = session.get_credentials()
assert creds is not None
reveal_type(creds) # Type of "creds" is "Credentials"
Please let me know if it works for you.
Ah, I see.
def load_credentials(self):
"""
Goes through the credentials chain, returning the first ``Credentials``
that could be loaded.
"""
# First provider to return a non-None response wins.
for provider in self.providers:
logger.debug("Looking for credentials via: %s", provider.METHOD)
creds = provider.load()
if creds is not None:
return creds
# If we got here, no credentials could be found.
# This feels like it should be an exception, but historically, ``None``
# is returned.
#
# +1
# -js
return None
Describe the bug session.get_credentials() has become optional, but it shoudn't.
To Reproduce Steps to reproduce the behavior:
boto3-stubs
mypy
/pyright
on the following code sampleActual output
Expected output
Additional context Your OS,
boto3-stubs
installation method,boto3
version, etc.