Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2430: lazy-param-initialization-2.patch

File lazy-param-initialization-2.patch, 2.6 KB (added by chrisz, 2 years ago)

Slightly modified patch

  • turbogears/widgets/base.py

     
    33import pkg_resources 
    44import warnings 
    55from turbogears import view, startup, config 
    6 from turbogears.util import setlike, to_unicode, copy_if_mutable, \ 
    7     get_package_name, request_available 
     6from turbogears.util import (setlike, to_unicode, copy_if_mutable, 
     7    get_package_name, request_available) 
    88from turbogears.i18n.utils import get_locale 
    99from turbogears.widgets.meta import MetaWidget, load_kid_template 
    1010from cherrypy import request 
     
    184184                setattr(self, param, copy_if_mutable(params.pop(param))) 
    185185 
    186186            else: 
    187                 if hasattr(self, param): 
    188                     # make sure we don't alter mutable class attributes 
    189                     value = copy_if_mutable(getattr(self.__class__, param), 
    190                                             True) 
    191                     if value[1]: 
    192                         # re-set it only if mutable 
    193                         setattr(self, param, value[0]) 
    194                 else: 
    195                     setattr(self, param, None) 
     187                # make sure we don't alter mutable class attributes 
     188                value, mutable = copy_if_mutable( 
     189                    getattr(self.__class__, param), True) 
     190                if mutable: 
     191                    # re-set it only if mutable 
     192                    setattr(self, param, value) 
    196193 
    197194        for unused in params.iterkeys(): 
    198195            warnings.warn('keyword argument "%s" is unused at %r instance' % ( 
  • turbogears/widgets/meta.py

     
    3737        for param in params: 
    3838            # Swap all params listed at 'params' with a ParamDescriptor 
    3939            try: 
    40                 dct[param_prefix+param] = dct[param] 
     40                dct[param_prefix + param] = dct[param] 
    4141                dct[param] = ParamDescriptor(param) 
    4242            except KeyError: 
    43                 # declared in a superclass, skip it... 
    44                 pass 
     43                for base in bases: 
     44                    if hasattr(base, param): 
     45                        break 
     46                else: 
     47                    # not declared in any superclass, let default be None 
     48                    dct[param_prefix + param] = None 
     49                    dct[param] = ParamDescriptor(param) 
    4550        params = list(params) 
    4651        dct['params'] = params 
    4752        if compound: