"Kevin Dangoor" <[EMAIL PROTECTED]> writes:

> Should unexpected parameters raise an exception every time?

Hmmm...  I'd try applying the saying "be liberal with what you get and strict
with what you send".  What I think is the best approach is:

     - if using something like **kw accept everything (even with validators
       missing for unexpected parameters)

     - if using keywords accept just what is declared in keywords and raise an
       exception on unexpected parameters, as Python does.

       >>> def testing(a = None, b = None):
       ...     print a
       ...     print b
       ... 
       >>> testing()
       None
       None
       >>> testing(a = 123)
       123
       None
       >>> testing(b = 123)
       None
       123
       >>> testing(a = 123, b = 234)
       123
       234
       >>> testing(c = 123)
       Traceback (most recent call last):
         File "<stdin>", line 1, in ?
       TypeError: testing() got an unexpected keyword argument 'c'
       >>> 

Why?  Because one might pass things outside of the declared form for some
other purpose.  If it is not declared in the validator, it is the developer's
responsability to validate it by hand (using formencode or not) and when you
declare just some keywords on your method's signature you are explicitly
stating that you don't want anything else.

-- 
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to