I think set_default_connection is a bit misleading, in that it "tries to create a connection from the environment"... To put this in pseudo-code:
def get_default_connection():
connection = <some pre-loaded connection already stored>
if not connection:
connection = <create a connection somehow from the environment>
if not connection:
connection = <create a connection from the environment another way>
if not connection:
raise EnvironmentError('Connection cannot be inferred from the environment :(')
return connection
def set_default_connection(connection=None):
<some safe place to store a connection> = connection # Yes, this could be None.
The idea being...
set_default_connection() sets a variable, that's all.
get_default_connection() goes through a list of possible ways to get a connection, raising an exception when we can't get one...
What we have today is:
set_default_connection() sets a variable and tries to come up with a magical connection from the environment if possible.
get_default_connection() only returns the variable
I'm sure this will be subject to a bunch of debate, but having a getter method also doing some setting seems really misleading to me.
I think
set_default_connectionis a bit misleading, in that it "tries to create a connection from the environment"... To put this in pseudo-code:The idea being...
set_default_connection()sets a variable, that's all.get_default_connection()goes through a list of possible ways to get a connection, raising an exception when we can't get one...What we have today is:
set_default_connection()sets a variable and tries to come up with a magical connection from the environment if possible.get_default_connection()only returns the variableI'm sure this will be subject to a bunch of debate, but having a getter method also doing some setting seems really misleading to me.