-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Currently, DEFAULT_SESSION and setup_default_session() are public members of boto3 module, but the caching _get_default_session() is not. I'd like to see this changed. I often write functions that look like
def my_func(arg1, arg2, session=None):
if not session:
session = boto3._get_default_session()some people write this as
def my_func(arg1, arg2, session=None):
if not session:
session = boto3but this breaks if I'm doing anything other than creating a client.
I can't write the following because it might not be initialized:
def my_func(arg1, arg2, session=None):
if not session:
session = boto3.DEFAULT_SESSIONI can't write the following because DEFAULT_SESSION might have been initialized to a custom value already:
def my_func(arg1, arg2, session=None):
if not session:
session = boto3.setup_default_session()I could copy in the logic from _get_default_session() (which only calls setup_default_session() if DEFAULT_SESSION isn't initialized) into each place where I do this, but why make me do that?
There doesn't seem to be any good reason for it to be private, especially given that the fields it operates on are public. I'd ask for the function to be renamed get_default_session() and an alias _get_default_session = get_default_session to be added for backward compatibility.