This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients eric.smith, madman bob, steven.daprano, vstinner
Date 2018-10-31.23:38:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541029133.04.0.788709270274.issue35123@psf.upfronthosting.co.za>
In-reply-to
Content
I don't see any problems that need solving.

My only interest in this is that I tend to think sentinels that are used for missing parameters should be exposed, and this isn't always an obvious consideration when designing an API.

For example, say there's a library that has a function:
open(name, type, [mode])

That is, mode is optional. I realize that in pure Python, I could find out what sentinel value they're using, unless they're playing tricks with args and kwargs. But maybe this is written in C.

Now, say I want to write a wrapper around this, called myopen, and always pass in "foo" for type.

I'd need to use my own sentinel:
_MISSING= object()
def myopen(name, mode=_MISSING)

But, how do I call open? In the past, I've done things like:
if mode is _MISSING:
  return open(name, "foo")
else:
  return open(name, "foo", mode)

That doesn't scale well if there are multiple optional parameters.

In any event, this just seems like a guideline we should be aware of when adding APIs.

Absent any concrete proposals for a "sentinel style guide", I don't think there's anything actionable here. I agree with Steven that it's a case-by-case thing. One size need not fit all.

As to the issue referenced by Victor: I'm not sure what a style guide would bring to the table. I think the issue of whether to use a second sentinel or not could be decided in this file alone, without needed a global decision.
History
Date User Action Args
2018-10-31 23:38:53eric.smithsetrecipients: + eric.smith, vstinner, steven.daprano, madman bob
2018-10-31 23:38:53eric.smithsetmessageid: <1541029133.04.0.788709270274.issue35123@psf.upfronthosting.co.za>
2018-10-31 23:38:53eric.smithlinkissue35123 messages
2018-10-31 23:38:52eric.smithcreate