Re: [Python-ideas] Add new `Symbol` type

2018-07-10 Thread Chris Angelico
On Wed, Jul 11, 2018 at 6:53 AM, Barry Warsaw wrote: > Guido van Rossum wrote on 7/6/18 08:31: >> >> Thanks for an interesting discussion. I would also urge people to limit >> the >> use of such sentinels for cases where it is *really* important to >> distinguish between, say, f(None) and f(). In

Re: [Python-ideas] Add new `Symbol` type

2018-07-10 Thread Barry Warsaw
Guido van Rossum wrote on 7/6/18 08:31: Thanks for an interesting discussion. I would also urge people to limit the use of such sentinels for cases where it is *really* important to distinguish between, say, f(None) and f(). In most cases using def f(arg=None) is fine, and often it is even a

Re: [Python-ideas] Add new `Symbol` type

2018-07-09 Thread Eric V. Smith
On 7/9/2018 5:01 PM, Brett Cannon wrote: On Fri, 6 Jul 2018 at 09:24 Eric V. Smith > wrote: On 7/6/2018 11:20 AM, Flavio Curella wrote: > I think this thread can be resolved as 'used unittest.mock.sentinel'. It > doesn't have 'global sentinels',

Re: [Python-ideas] Add new `Symbol` type

2018-07-09 Thread Brett Cannon
On Fri, 6 Jul 2018 at 09:24 Eric V. Smith wrote: > On 7/6/2018 11:20 AM, Flavio Curella wrote: > > I think this thread can be resolved as 'used unittest.mock.sentinel'. It > > doesn't have 'global sentinels', but I'm not convinced they are actually > > necessary, since `mock.sentinel` objects

Re: [Python-ideas] Add new `Symbol` type

2018-07-06 Thread Steven D'Aprano
On Thu, Jul 05, 2018 at 05:26:36PM -0700, Nathaniel Smith wrote: > I think the name "symbol" here is pretty confusing. It comes > originally from Lisp, where it's used to refer to an interned-string > data type. Even if Lisp was the first programming language to use the term for a data type

Re: [Python-ideas] Add new `Symbol` type

2018-07-06 Thread Eric V. Smith
On 7/6/2018 11:20 AM, Flavio Curella wrote: I think this thread can be resolved as 'used unittest.mock.sentinel'. It doesn't have 'global sentinels', but I'm not convinced they are actually necessary, since `mock.sentinel` objects with the same name compare as equal. Thanks to Nathaniel, I now

Re: [Python-ideas] Add new `Symbol` type

2018-07-06 Thread Guido van Rossum
Thanks for an interesting discussion. I would also urge people to limit the use of such sentinels for cases where it is *really* important to distinguish between, say, f(None) and f(). In most cases using def f(arg=None) is fine, and often it is even a virtue that passing None or omitting an

Re: [Python-ideas] Add new `Symbol` type

2018-07-06 Thread Flavio Curella
@Nathaniel Smith: > I think the name "symbol" here is pretty confusing. It comes originally from Lisp > The thing you're talking about is what Python devs call a "sentinel" object. Thank you for clarifying. I don't know much about Lisp, and I definitely appreciate the historical context that

Re: [Python-ideas] Add new `Symbol` type

2018-07-06 Thread Giampaolo Rodola'
Historically this has always been achieved by using: _default = object() def fun(arg=_default): if arg is not _default: ...which does its job just fine. If you need something like this you're typically a medium/advanced Python user so you either already know about it or

Re: [Python-ideas] Add new `Symbol` type

2018-07-06 Thread Michael Foord
On Fri, 6 Jul 2018 at 07:30, Steven D'Aprano wrote: > On Thu, Jul 05, 2018 at 02:38:47PM -0500, Flavio Curella wrote: > > More than once I've found myself wanting to create a 'sentinel' value. > The > > most common use case is to differentiate between an argument that has not > > been provided,

Re: [Python-ideas] Add new `Symbol` type

2018-07-06 Thread Steven D'Aprano
On Thu, Jul 05, 2018 at 02:38:47PM -0500, Flavio Curella wrote: > More than once I've found myself wanting to create a 'sentinel' value. The > most common use case is to differentiate between an argument that has not > been provided, and an argument provided with the value `None`. [...] > Is this

Re: [Python-ideas] Add new `Symbol` type

2018-07-05 Thread Nathaniel Smith
On Thu, Jul 5, 2018 at 1:25 PM, Flavio Curella wrote: > >> What functionality does such a thing actually need? > > I think the requirements should be: > * The resulting symbol behave exactly like None. IE: the symbol should not > be an instance of object, but an instance of its own class > * A

Re: [Python-ideas] Add new `Symbol` type

2018-07-05 Thread Flavio Curella
> What functionality does such a thing actually need? I think the requirements should be: * The resulting symbol behave exactly like None. IE: the symbol should not be an instance of object, but an instance of its own class * A symbol can optionally be globally unique. * Two symbols created by

Re: [Python-ideas] Add new `Symbol` type

2018-07-05 Thread Joseph Jevnik
I have also wanted sentinel objects many times. These are often useful for creating a "Not Specified" default value when explicitly passing `None` has semantic meaning. There are a few issues with the `sentinel = object()` code. One is that they don't repr well so they make debugging harder.

Re: [Python-ideas] Add new `Symbol` type

2018-07-05 Thread Ed Kellett
Hi! On 2018-07-05 20:38, Flavio Curella wrote: > More than once I've found myself wanting to create a 'sentinel' value. The > most common use case is to differentiate between an argument that has not > been provided, and an argument provided with the value `None`. I generally do something like

[Python-ideas] Add new `Symbol` type

2018-07-05 Thread Flavio Curella
More than once I've found myself wanting to create a 'sentinel' value. The most common use case is to differentiate between an argument that has not been provided, and an argument provided with the value `None`. This would be solvable by implementing something similar to what JavaScript calls