Is it explicitly specified?

Steve Holden steve at holdenweb.com
Sun Feb 3 10:19:22 EST 2008


Diez B. Roggisch wrote:
> Bjoern Schliessmann schrieb:
>> mario ruggier wrote:
>>
>>> It may sometimes be useful to make use of the conceptual
>>> difference between these two cases, that is that in one case the
>>> user did not specify any key and in the other the user explicitly
>>> specified the key to be None.
>> Do you have an example where this might be useful?
> 
> Any situation in which there would otherwise lots of documentation 
> needed to inform the user that the sentinel value is something else than 
> None.
> 
> Take something like this as an example:
> 
> def update_user(some, values, nullable_value=sentinel):
>      # first, work with some and values
>      ...
>      # then, on something actually being passed to nullable_value
>      if nullable_value is not sentinel:
>         connection.cursor().execute("update table set value = ?", 
> nullable_value)
> 
> 
> 
> I've seen this before, in code from e.g. Alex Martelli.
> 
Sure, but the OP's question was "Is there any way to tell between 
whether a keyword arg has been explicitly specified (to the same value 
as the default for it)". We've drifted a long way from that, since the 
code you demonstrate doesn't detect an explicit call with 
nullable_value==sentinel -- the reason being, I submit, that there is no 
use case for such code.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list