Re: [Python-ideas] Python docs: page: In what ways in None special

(Sorry to break threading on this. In a fit of idiocy I deleted the original email before realising I wanted to reply.) First off, thanks for doing this Jonathan. Documentation is usually a thankless task, so we ought to start by thanking you! I have a few comments on both content and style, good and bad. Starting with style, I notice you tend to write in short sentences. This is generally a good thing, but sometimes you make them too short. This gets really visible when you start sentences with "And" or "But"; my old English teacher would have menaced you with a ruler for such bad grammar. You can start a sentence with a conjunction, but it adds extra emphasis that you don't usually want. The start of the "Why None?" section is a good example. It reads like: "Sometimes a value is required. But (pay careful attention to this, it's important and there will be a quiz later) we're not able to provide one." I exaggerate for effect, of course, but it would read more easily as: "Sometimes a value is required but we're not able to provide one." On 'None is a constant': Erm. I think you've got carried away with simplifying this and gone down a blind alley. None is a literal, and like any other literal can't be rebound. Either this entire section is irrelevant or you meant to explain that there is only one "NoneType" object. Constant is a bit of a loaded term in Python, and I think you've fallen foul of it here. On 'None is the default return value': I really dislike the term "falls off the bottom". I can't think of anything similarly short and expressive, but I grimaced when I saw it. The 'list gotcha' is a good example of how None is used as the default return value and why programmers should pay attention, but it doesn't deserve it's own subsection. It's a direct consequence of None being the return value. On 'None can signal failure': Here's where I think None stops being special in the document. None can signal failure. So False, 0, an empty string, a negative number or pretty much anything else. If you want to have a section on how None is used, that great, but having this in the section "How None is special" is just wrong. On 'None as a placeholder default': Ditto. It's common to use None as a placeholder for a mutable type; explaining that common gotcha here would be good. Epigraphs: If you're going to quote Sherman, you need to expand on the uniqueness of None. Not doing that just makes it look irrelevant. It's not irrelevant, it's a tigger [1] [1] Misquoting Michael Flanders from the introduction to "The Hippopotamus Song" on "At The Drop Of A Hat". -- Rhodri James *-* Kynesim Ltd

On Tue, Aug 14, 2018 at 10:45 AM, Rhodri James <rhodri@kynesim.co.uk> wrote:
no, it's not -- None is keyword, and just like any other keyword, it can't be re-bound. However, every other keyword I tried to rebind results in a generic: SyntaxError: invalid syntax (except None, True, and False) which I suppose is because while None is a keyword, it can be used pretty much anywhere any other name can be used (as opposed to say, def) Either this entire section is irrelevant or you meant to explain that there
yes, I think "singleton" is the word you want here, though it is a bi CS-y :-( -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

On Wed, Aug 15, 2018 at 9:09 AM, Chris Barker via Python-ideas <python-ideas@python.org> wrote:
Yeah. That's the difference between "keywords that are syntactically special" and "keywords that represent specific values". Most keywords define syntax (you mention "def", and similarly "if", "global", "import") or are operators ("and", "if", "is not"); the ones that could theoretically be assigned to are defined in the grammar as forms of atom. atom: ('(' [yield_expr|testlist_comp] ')' | '[' [testlist_comp] ']' | '{' [dictorsetmaker] '}' | NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
Interestingly, even though the first example specifically says "Ellipsis", it's perfectly acceptable to assign to that name:
Note also that the rules are slightly different in Python 2; True and False are ordinary builtins, and "..." has meaning only inside a subscript, so trying to assign to it makes as much sense as "<> = 1". The special non-assignable status of None is therefore shared by three other values; it's still special, but it's not unique. The same is true of the behaviour of "if None:" - since it's a keyword and cannot be assigned to, it will always have the same value, and since it's an immutable value, it will always have the same truthiness, and since the 'if' statement is always false, the bytecode can be optimized away. So that's also not unique to None, but is behaviour shared by other literals. (Only literals though - neither "if []:" nor "if {}:" is optimized out, at least in CPython 3.7.) ChrisA

On 15/08/18 00:09, Chris Barker wrote:
It's both, really. In many ways it's only a keyword because Python doesn't otherwise have a way of creating non-rebindable names. It's purpose is to represent the singular object of NoneType, and in that sense it's a literal as much as [] or "". -- Rhodri James *-* Kynesim Ltd

None is keyword, and just like any other keyword, it can't be re-bound.
it's only a keyword because Python doesn't otherwise have a way of creating non-rebindable names. It's purpose is to represent the singular object of NoneType, and in that sense it's a literal as much as [] or "".
We’re getting kind of pedantic here, but no, it’s not “as much as” — [] and “” create new instances of a list or string. For the purposes of this document, however, these are pretty esoteric distinctions. What the docs should make clear is that None ( and True and False ) is a singleton— None will always refer to the SAME None object. And that can be demonstrated by showing that you can’t rebind the name None. But I think it’s misleading to say that that is the same as: 42 = “something else” None is syntactical a name like any other — what’s special about is that it can’t be rebound. -CHB
-- Rhodri James *-* Kynesim Ltd

Since I already spent a bunch of time on this, I did a PR: https://github.com/jfine2358/py-jfine2358/pull/2 further discussion should probably be in that PR / repo -CHB On Wed, Aug 15, 2018 at 9:02 AM, Chris Barker - NOAA Federal < chris.barker@noaa.gov> wrote:
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

On Tue, Aug 14, 2018 at 10:45 AM, Rhodri James <rhodri@kynesim.co.uk> wrote:
no, it's not -- None is keyword, and just like any other keyword, it can't be re-bound. However, every other keyword I tried to rebind results in a generic: SyntaxError: invalid syntax (except None, True, and False) which I suppose is because while None is a keyword, it can be used pretty much anywhere any other name can be used (as opposed to say, def) Either this entire section is irrelevant or you meant to explain that there
yes, I think "singleton" is the word you want here, though it is a bi CS-y :-( -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

On Wed, Aug 15, 2018 at 9:09 AM, Chris Barker via Python-ideas <python-ideas@python.org> wrote:
Yeah. That's the difference between "keywords that are syntactically special" and "keywords that represent specific values". Most keywords define syntax (you mention "def", and similarly "if", "global", "import") or are operators ("and", "if", "is not"); the ones that could theoretically be assigned to are defined in the grammar as forms of atom. atom: ('(' [yield_expr|testlist_comp] ')' | '[' [testlist_comp] ']' | '{' [dictorsetmaker] '}' | NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
Interestingly, even though the first example specifically says "Ellipsis", it's perfectly acceptable to assign to that name:
Note also that the rules are slightly different in Python 2; True and False are ordinary builtins, and "..." has meaning only inside a subscript, so trying to assign to it makes as much sense as "<> = 1". The special non-assignable status of None is therefore shared by three other values; it's still special, but it's not unique. The same is true of the behaviour of "if None:" - since it's a keyword and cannot be assigned to, it will always have the same value, and since it's an immutable value, it will always have the same truthiness, and since the 'if' statement is always false, the bytecode can be optimized away. So that's also not unique to None, but is behaviour shared by other literals. (Only literals though - neither "if []:" nor "if {}:" is optimized out, at least in CPython 3.7.) ChrisA

On 15/08/18 00:09, Chris Barker wrote:
It's both, really. In many ways it's only a keyword because Python doesn't otherwise have a way of creating non-rebindable names. It's purpose is to represent the singular object of NoneType, and in that sense it's a literal as much as [] or "". -- Rhodri James *-* Kynesim Ltd

None is keyword, and just like any other keyword, it can't be re-bound.
it's only a keyword because Python doesn't otherwise have a way of creating non-rebindable names. It's purpose is to represent the singular object of NoneType, and in that sense it's a literal as much as [] or "".
We’re getting kind of pedantic here, but no, it’s not “as much as” — [] and “” create new instances of a list or string. For the purposes of this document, however, these are pretty esoteric distinctions. What the docs should make clear is that None ( and True and False ) is a singleton— None will always refer to the SAME None object. And that can be demonstrated by showing that you can’t rebind the name None. But I think it’s misleading to say that that is the same as: 42 = “something else” None is syntactical a name like any other — what’s special about is that it can’t be rebound. -CHB
-- Rhodri James *-* Kynesim Ltd

Since I already spent a bunch of time on this, I did a PR: https://github.com/jfine2358/py-jfine2358/pull/2 further discussion should probably be in that PR / repo -CHB On Wed, Aug 15, 2018 at 9:02 AM, Chris Barker - NOAA Federal < chris.barker@noaa.gov> wrote:
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
participants (4)
-
Chris Angelico
-
Chris Barker
-
Chris Barker - NOAA Federal
-
Rhodri James