shmeedogg
If we want explicit kwargs (a big 'if' since many of the suggestions in this thread are to give up on that idea), then we need some value to distinguish it from None.
True, let me try to clarify. There might be some attributes like `admin` that you don't want twiddled via the `update` method but rather mutated via a setter function. In this case, the signature of the `update` function would be helping to indicate that.
(A better example might be the attribute `active` with two methods called `activate` and `deactivate` that send emails and what-not.)
But until then, how can two different libraries agree to use the exact same instance of `NotSet` without some standard package defining it?
The goal is really to be able to 'proxy' this do-not-care condition from applications into libraries in a standardized way.
I'd worry that this approach could end up being even more confusing.
True there is some work in keeping the two synchronized, but there are benefits.
First, unexpected arguments are immediately caught since they throw a TypeError.
Without this, you either have to manually check for unexpected keys (probably doing a set difference with `allowed_keys` or something) or you just silently pass through unrecognized attributes, probably causing strange behavior later on.
Second, you are forced to say explicitly which attributes are modifiable. To draw from the 'person' example, `name` and `age` might be modifiable, but `admin` might be protected. That would be made abundantly clear by `update(person, name=NotSet, age=NotSet)`, but less so, by `update(person, attrs)` or `update(person, kwargs)`.
A clear docstring would help, but I'd prefer to have the code just fail-fast on this unexpected input.
The aspect that interests me is that this is a problem that crops up occasionally in different Python projects and there doesn't seem to be a recognized best-practice for addressing it.
(The `kwargs` approach seems like the most common but has all the downsides I mentioned.)
I'd love an approach that used the standard library, but there doesn't seem to be a type-agnostic approach. float('nan') won't make sense for other types, and using `types.NoneType` instead of `None` seems even less understandable.
Notset: A Do-Not-Care value for Python
Show HN: Mockstrap, a Twitter Bootstrap Sandbox
You could use this, for example, to test that your mobile application is properly caching HTTP requests (it would be noticeably slower, even with a fast connection, because the request is guaranteed to take at least 2 seconds).
The specific use case I had in mind when I created it was testing the HTTP caching that will be used internally by the OpenStack "glance" project.
ReallySlowSite.com
Useful for developing/testing HTTP caching libraries.