Home | Trees | Indices | Help |
---|
|
object --+ | Let
A Let allows for temporarily storing passed arguments in the _settings member of a target object for the duration of the contextmanager's scope Implementation on a factory class class MyThingFactory(object): def __init__(self): self._settings = {} def generate_thing(self): # do something here new_obj = Thing() for k,v in self._settings.iteritems(): setattr(new_obj, k, v) return new_obj def let(self, **kwds): return Let(self, kwds) Calling code that wants to temporarily customize the Thing objects that are returned by the factory: fac = MyThingFactory() with fac.let(this="that", foo="bar"): a_thing = fac.generate_thing() self.assertEqual(a_thing.this, "that")
|
|||
|
|||
|
|||
|
|||
Inherited from |
|
|||
Inherited from |
|
x.__init__(...) initializes x; see help(type(x)) for signature
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Jun 29 08:51:16 2017 | http://epydoc.sourceforge.net |