[issue39971] Error on documentation - Quick fix.
New submission from Diogo Flores <dxflores@outlook.com>: Hello, 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, Diogo Please check below for the commands issued: # https://docs.python.org/3/howto/functional.html#generator-expressions-and-li...
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'
---------- assignee: docs@python components: Documentation messages: 364247 nosy: docs@python, dxflores priority: normal severity: normal status: open title: Error on documentation - Quick fix. versions: Python 3.8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39971> _______________________________________
Eric V. Smith <eric@trueblade.com> added the comment: I don't think that was meant to be a literal example. I think that "..." here means "and other strings". ---------- nosy: +eric.smith _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39971> _______________________________________
Diogo Flores <dxflores@outlook.com> added the comment: 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, Diogo ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39971> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: 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. ---------- nosy: +terry.reedy stage: -> needs patch title: Error on documentation - Quick fix. -> Error in functional how-to example versions: +Python 3.7, Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39971> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39971> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: 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'. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39971> _______________________________________
participants (3)
-
Diogo Flores -
Eric V. Smith -
Terry J. Reedy