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

Collections - ChainMap - Documentation example wrong order line #75258

Closed
MarcosSoutullo mannequin opened this issue Jul 29, 2017 · 3 comments
Closed

Collections - ChainMap - Documentation example wrong order line #75258

MarcosSoutullo mannequin opened this issue Jul 29, 2017 · 3 comments
Assignees
Labels
build The build process and cross-build docs Documentation in the Doc dir

Comments

@MarcosSoutullo
Copy link
Mannequin

MarcosSoutullo mannequin commented Jul 29, 2017

BPO 31075
Nosy @rhettinger

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 = 'https://github.com/rhettinger'
closed_at = <Date 2017-09-07.21:26:09.399>
created_at = <Date 2017-07-29.12:24:17.171>
labels = ['build', 'invalid', 'docs']
title = 'Collections - ChainMap - Documentation example wrong order line'
updated_at = <Date 2017-09-07.21:26:09.398>
user = 'https://bugs.python.org/MarcosSoutullo'

bugs.python.org fields:

activity = <Date 2017-09-07.21:26:09.398>
actor = 'rhettinger'
assignee = 'rhettinger'
closed = True
closed_date = <Date 2017-09-07.21:26:09.399>
closer = 'rhettinger'
components = ['Documentation']
creation = <Date 2017-07-29.12:24:17.171>
creator = 'Marcos Soutullo'
dependencies = []
files = []
hgrepos = []
issue_num = 31075
keywords = []
message_count = 3.0
messages = ['299465', '299478', '299484']
nosy_count = 3.0
nosy_names = ['rhettinger', 'docs@python', 'Marcos Soutullo']
pr_nums = []
priority = 'low'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'compile error'
url = 'https://bugs.python.org/issue31075'
versions = ['Python 3.6']

@MarcosSoutullo
Copy link
Mannequin Author

MarcosSoutullo mannequin commented Jul 29, 2017

Hello,

I have been taking a look into your ChainMap collections documentation (https://docs.python.org/3.6/library/collections.html?highlight=collections#collections.ChainMap), specifically the third code example on "8.3.1.1. ChainMap Examples and Recipes"
that clearly describe and illustrate a use case for the ChainMap class. However, I found a very small code issue in regards to how the sample code (line 7) is presented to the reader. Please refer to the code compilation below:

Line 7 >>> d['x']                # Get first key in the chain of contexts
raise KeyError(key)
KeyError: 'x'
Line 8 >>> d['x'] d['x'] = 1            # Set value in current context

The key named 'x' had not been initialised yet and of course, the compiler is complaining. It should be the other way around.

Line 8 >>> d['x'] = 1   # Set value in current context
Line 7 >>> d['x']       # Get first key in the chain of contexts

Many thanks for the great work you do with Python,

Marcos S.

@MarcosSoutullo MarcosSoutullo mannequin added docs Documentation in the Doc dir build The build process and cross-build labels Jul 29, 2017
@rhettinger
Copy link
Contributor

-0

The code block was originally intended to just be a table of patterns, not meant to be executed sequentially. It followed the traditional presentation order (getitem, __setitem__, followed by __delitem__).

If we do change this, then the subsequent "k in d" example should also be changed to "'x' in d" because k isn't defined.

@rhettinger
Copy link
Contributor

Many thanks for the great work you do with Python,

Thanks for the kudos. Also, thanks for the close reading of the docs.

@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
build The build process and cross-build docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

1 participant