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

Denis Laxalde denis@laxalde....
Thu Apr 19 14:08:34 CDT 2012

Nathaniel Smith 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"]: ...

AFAICT, that dictionary is not modified. Yet I am now convinced that it
is safer to use None.


More information about the SciPy-Dev mailing list