Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There are inconsitencies in the treatment of True, False, None, and __debug__ keywords in the docs #78645

Open
jfine2358 mannequin opened this issue Aug 22, 2018 · 6 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@jfine2358
Copy link
Mannequin

jfine2358 mannequin commented Aug 22, 2018

BPO 34464
Nosy @bitdancer, @serhiy-storchaka, @matrixise, @jfine2358

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2018-08-22.19:08:50.656>
labels = ['3.8', 'type-feature', '3.7', 'docs']
title = 'There are inconsitencies in the treatment of True, False, None, and __debug__ keywords in the docs'
updated_at = <Date 2019-03-15.21:08:19.424>
user = 'https://github.com/jfine2358'

bugs.python.org fields:

activity = <Date 2019-03-15.21:08:19.424>
actor = 'matrixise'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2018-08-22.19:08:50.656>
creator = 'jfine2358'
dependencies = []
files = []
hgrepos = []
issue_num = 34464
keywords = []
message_count = 6.0
messages = ['323904', '323905', '323907', '336091', '336099', '338035']
nosy_count = 5.0
nosy_names = ['r.david.murray', 'docs@python', 'serhiy.storchaka', 'matrixise', 'jfine2358']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue34464'
versions = ['Python 3.7', 'Python 3.8']

@jfine2358
Copy link
Mannequin Author

jfine2358 mannequin commented Aug 22, 2018

The identifiers True, False, None and __debug__ are keywords in the language.  For example
>>> __debug__ = __debug__
SyntaxError: assignment to keyword
  1. The page constants.html incorrectly says then are in the built-in namespace. Some of them were, once.

  2. The list keyword.kwlist does not contain __debug__. (Problem in Lib/keyword.py.)

  3. https://docs.python.org/3/reference/datamodel.html for None, NotImplemented, etc.

  4. There may be other places that need looking at.

See also: https://github.com/jfine2358/py-jfine2358/blob/master/docs/none-is-special.md

Credit: The __debug__ problem arises from Steve D'Aprano's message

https://mail.python.org/pipermail/python-ideas/2018-August/052917.html
The std lib contains a test that this correctly raises SyntaxError:
def f(*, x=lambda __debug__:0): pass

@jfine2358 jfine2358 mannequin added 3.7 (EOL) end of life 3.8 only security fixes labels Aug 22, 2018
@jfine2358 jfine2358 mannequin assigned docspython Aug 22, 2018
@jfine2358 jfine2358 mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Aug 22, 2018
@jfine2358
Copy link
Mannequin Author

jfine2358 mannequin commented Aug 22, 2018

I'm happy to work on improving the text here. I'm new to contributing to Python. I'm being mentored to work on bpo-34431.

Once I'm done with that, I'll be better placed to contributed to this issue.

@bitdancer
Copy link
Member

I've removed 2.7 since those constants are not keywords in 2.7 (although None and __debug__ do raise syntax errors even in 2.7, they are not keywords there). Which is almost certainly why the docs treat them inconsistently (leftovers from before they weren't keywords).

We only update docs for the actively maintained versions, so I've removed everything before 3.6. I also tried to clarify the issue in the title.

I don't know why you mention NotImplemented, that's not a keyword.

The issue with __debug__ and keywords.py probably requires a code change, since that file is auto-generated. Please open a separate issue for that.

Thanks for wanting to improve python!

@bitdancer bitdancer changed the title docs: keywords are special - eg constants.html There are inconsitencies in the treatment of True, False, None, and __debug__ keywords in the docs Aug 22, 2018
@matrixise
Copy link
Member

Hi @david,

Maybe we could remove 3.6 from the list because 3.6 is in security mode and not bugfix.

Is there a security issue with this bug?

@serhiy-storchaka
Copy link
Member

__debug__ is not a keyword. And the error message has been changed in 3.8.

But it is a special enough. You can not use this name in any assignment context:

>>> __debug__ = 1
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> for __debug__ in []: pass
... 
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> with cm() as __debug__: pass
... 
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> class __debug__: pass
... 
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> def __debug__(): pass
... 
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> def foo(__debug__): pass
... 
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> import __debug__
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__

You can not even assign to an attribute named __debug__!

>>> x.__debug__ = 1
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__

The assignment operator is the only exception here, and this looks like a bug.

@matrixise
Copy link
Member

@serhiy

The issue about the assigment operator is closed https://bugs.python.org/issue36052

could we close this issue?

thank you

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants