On Sep 7, 5:02 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> >> Note that any callable parameters that you pass this way are
> >> automatically called (without any additional arguments) - I think that
> >> was one of your questions.
> >
> > Poor design. I hope the ToscaWidgets people are reading.
>
> I don't agree. The possibility to pass callables that get auto-invoked
> is very convenient for a great deal of use-cases.
Yes, it looks like a hack someone put in to suit several use-cases,
while ignoring the effects it might have on those who don't share that
use-case.
Having callables auto-invoked is fine, but they shouldn't be bundled
inline with things you generally don't want to be called.
Generally speaking, I think most programmers would say that this sort
of special case code is bad form.
> Of course one could
> come up with other approaches - a common subclass these parameters must
> be inherited from for example. Or some other javaish solution.
How about a callable_params member, defined at the Widget's class
level. This would be a subset of params, stating which ones need
calling at display time.
# logic for managing the params attribute
for param in self.__class__.params:
if param in params:
param_value = params[param]
else:
# if the param hasn't been overridden (passed as a
keyword
# argument inside **params) put the corresponding
instance
# value inside params.
param_value = getattr(self, param, None)
if param in self.__class__.callable_params:
param_value = param_value()
This also fixes what looks like a bug (in my version of TG, at least),
namely that non-overridden params don't get called.
> And all you need to circumvene the automatism is a simple
>
> lamdba: my_function
I don't like fixing hacks with a second hack. And this wouldn't avoid
the initial problem of the user wondering why their output doesn't
match what they expect. Perhaps they will instantly notice that it's
because their item is callable, but perhaps they won't.
> Additionally, see my other post for a way to create callables for use in
> the templates.
Yes, that should come in useful, thanks.
--
Ben Sizer
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---