bigmlcom/python — pull request #9 by njwilson (2012-07-08 01:43:38+00:00)
Title: Change default username/api_key args to None

In Python, the values of default arguments are created once when the
function/method is defined; they are not re-evaluated each time the
function/method is called.

By using `username=os.environ['BIGML_USERNAME']` as the default argument
to BigML's constructor, the value of the BIGML_USERNAME environment
variable *at the time the module is imported* will remain the default
value until the interpreter exits, even if the value of the environment
variable changes.

Before this change:

>>> from bigml.api import *
>>> BigML(api_key='***').auth
'?username=njwilson;api_key=***;'
>>> os.environ['BIGML_USERNAME'] = 'joebob'
>>> BigML(api_key='***').auth
'?username=njwilson;api_key=***;' <--- Should be 'joebob'

After this change:

>>> from bigml.api import *
>>> BigML(api_key='***').auth
'?username=njwilson;api_key=***;'
>>> os.environ['BIGML_USERNAME'] = 'joebob'
>>> BigML(api_key='***').auth
'?username=joebob;api_key=***;'

In practice, it probably doesn't matter in this case as the environment
variables shouldn't be changing. However, I ran into a problem when I
was automatically generating some API documentation and the output was
showing:

class bigml.api.BigML(username='njwilson', ...)

(The documentation contained my username and API key)