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.

Title: [doc] Error in functional how-to example
Type: Stage: patch review
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, dxflores, eric.smith, rhettinger, slateny, terry.reedy
Priority: normal Keywords: easy, patch

Created on 2020-03-15 16:39 by dxflores, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 32172 open slateny, 2022-03-29 02:37
Messages (6)
msg364247 - (view) Author: Diogo Flores (dxflores) * Date: 2020-03-15 16:39

A code example from the 'functional programming how-to' raises an error.

The simplest fix would be to remove the Ellipsis object from the 'line_list'.

Thank you,

Please check below for the commands issued:


>>> line_list = ['  line 1\n', 'line 2  \n', ...]
>>> # Generator expression -- returns iterator
>>> stripped_iter = (line.strip() for line in line_list)
>>> # List comprehension -- returns list
>>> stripped_list = [line.strip() for line in line_list]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
AttributeError: 'ellipsis' object has no attribute 'strip'
msg364275 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-03-16 01:46
I don't think that was meant to be a literal example. I think that "..." here means "and other strings".
msg364346 - (view) Author: Diogo Flores (dxflores) * Date: 2020-03-16 17:50
Agreed, Eric. Nevertheless, I think that this example might raise unnecessary confusion to someone new to Python, and hence the reason why I decided to open the issue. Anyhow, I trust your judgement and please feel free to leave things as is and close this issue.

PS: I really the work you did with dataclasses, and I actually explored the idea further with a small (300 LoC) library that adds runtime type checking for instances of dataclasses - if you are ever curious you can find the code on my GitHub at /dxflores/invis.

Thank you,
msg364708 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-20 19:17
In think examples should run and that '...' should be replaced by something like "' \n', ''".  The blank string looks ahead to the next example, which adds ' if line != ""' to the comprehension.
msg364709 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-20 19:25
Working on PR.  The example 1 further on has a stray meaningless ellipsis.

             for expr3 in sequence3 ...
             if condition3

Perhaps this was meant to follow the next line, but I will remove it.
msg364710 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-20 19:44
Looking around further, examples meant to be executable as is are given interactive prompts and needed doctest directives

    >>> gen  #doctest: +ELLIPSIS
    <generator object generate_ints at ...>

I think that this example should get the same treatment.  Non-executable examples are usually clearly non-executable because then contain undefined names line 'expr2' and 'sequence2', whereas this example starts by defining 'line_list'.
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84152
2022-03-29 07:57:47eric.smithsetnosy: + rhettinger
2022-03-29 02:37:57slatenysetkeywords: + patch
nosy: + slateny

pull_requests: + pull_request30250
stage: needs patch -> patch review
2022-03-20 20:24:29iritkatrielsetkeywords: + easy
title: Error in functional how-to example -> [doc] Error in functional how-to example
versions: + Python 3.10, Python 3.11, - Python 3.7, Python 3.8
2020-03-20 19:44:24terry.reedysetmessages: + msg364710
2020-03-20 19:25:10terry.reedysetmessages: + msg364709
2020-03-20 19:17:32terry.reedysetnosy: + terry.reedy
title: Error on documentation - Quick fix. -> Error in functional how-to example
messages: + msg364708

versions: + Python 3.7, Python 3.9
stage: needs patch
2020-03-16 17:50:37dxfloressetmessages: + msg364346
2020-03-16 01:46:10eric.smithsetnosy: + eric.smith
messages: + msg364275
2020-03-15 16:39:23dxflorescreate