petered / defer-defaults

0 stars 1 forks source link

What to use as the sentinel object? #1

Open jfine2358 opened 5 years ago

jfine2358 commented 5 years ago

Current code has deferred = object() as the sentinel. Sometimes current practice is None. I thought subclassing None might give the best of both worlds. But that can't be done: see my post https://mail.python.org/pipermail/python-ideas/2018-July/052366.html

petered commented 5 years ago

The thing about None is that it may have another meaning that you might actually want to pass down e.g. post_processor=None to me would intuitively indicate - "do not do any post-processing", not "defer to the default post-processor". I find arg = deferred to be more explicit in its intent.

The one problem I can think of with deferred = object() is that (I think) is that if somehow a deferred object is serialized and deserialized (e.g. when doing multiprocessing) it will no longer be equal to the "deferred" object that lives in the module. Maybe class deferred: pass is the way to go?

jfine2358 commented 5 years ago

Perhaps provide Defer = None, for those who want it. This would allow them to both provide the value and the specific semantic intent.

T.S. Eliot says [every] cat must have THREE DIFFERENT NAMES (see https://allpoetry.com/The-Naming-Of-Cats).

This would also allow us to proceed with coding, while keeping this issue open.

petered commented 5 years ago

The "gotcha" I see with Defer = None is that people may not realize that having arg = None actually means "defer to default value in lower-level function" - which could cause bugs in cases where "None" is used to mean something else (as with the postprocessing example). Another poet once said: "There should be one-- and preferably only one --obvious way to do it."

petered commented 5 years ago

Would you be ok with class Defer: pass?

jfine2358 commented 5 years ago

Well, that's not a problem until we have a deferral module. So let's get the module written, and then revisit. I didn't expect or intend this to become a rabbit hole.

petered commented 5 years ago

ok