[SciPy-Dev] PR #196: simplification of optimization wrappers

Nathaniel Smith njs@pobox....
Thu Apr 19 09:31:53 CDT 2012

On Thu, Apr 19, 2012 at 3:28 PM, Denis Laxalde <denis@laxalde.org> wrote:
> josef.pktd@gmail.com wrote:
>> I just saw that the options use a mutable keyword, dict.
>> Are we running into problems? It might be safer to set it to None
>> instead of an empty dict, given that an empty dict doesn't make a more
>> informative signature either.
> I'm not sure to see the problem but, AFAICT, setting its default value
> to None would not prevent an existing options dictionary (or any
> mutable object) that would be passed as an argument to be modified. It
> seems there might a problem iff the default value is not an empty
> dictionary.
> At least, {} as a default value ensures that dictionary methods
> always work.

{} as a default value is fine iff you are careful to treat the
passed-in dictionary as read-only. E.g. this is bad

def dosomething(options={}):
  options.setdefault("quickly", True)
  if options["quickly"]: ...

-- Nathaniel

More information about the SciPy-Dev mailing list