GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [doc] Error in functional how-to example · Issue #84152 · python/cpython

[doc] Error in functional how-to example #84152

New issue
Copy link
New issue
Copy link
Closed
Closed
[doc] Error in functional how-to example#84152
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc direasy

Description

dxflores
mannequin
opened on Mar 15, 2020
Issue body actions
BPO 39971
Nosy @rhettinger, @terryjreedy, @ericvsmith, @dxflores, @slateny
PRs
  • bpo-39971: Change examples to be runnable #32172
  • 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 2020-03-15.16:39:23.863>
    labels = ['easy', '3.11', '3.9', '3.10', 'docs']
    title = '[doc] Error in functional how-to example'
    updated_at = <Date 2022-03-29.07:57:47.314>
    user = 'https://github.com/dxflores'

    bugs.python.org fields:

    activity = <Date 2022-03-29.07:57:47.314>
    actor = 'eric.smith'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2020-03-15.16:39:23.863>
    creator = 'dxflores'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39971
    keywords = ['patch', 'easy']
    message_count = 6.0
    messages = ['364247', '364275', '364346', '364708', '364709', '364710']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'terry.reedy', 'eric.smith', 'docs@python', 'dxflores', 'slateny']
    pr_nums = ['32172']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue39971'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    Next
    1. dxflores commented on Mar 15, 2020

      @dxflores
      dxfloresmannequin
      on Mar 15, 2020
      MannequinAuthor
      More actions

      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-list-comprehensions

      >>> 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'
    2. dxflores
      added
      3.8 (EOL)end of lifeend of life
      on Mar 15, 2020
    3. dxflores
      assigned
      docspython
      on Mar 15, 2020
    4. dxflores
      added
      docsDocumentation in the Doc dirDocumentation in the Doc dir
      3.8 (EOL)end of lifeend of life
      on Mar 15, 2020
    5. dxflores
      assigned
      docspython
      on Mar 15, 2020
    6. dxflores
      added
      docsDocumentation in the Doc dirDocumentation in the Doc dir
      on Mar 15, 2020
    7. ericvsmith commented on Mar 16, 2020

      @ericvsmith
      ericvsmith
      on Mar 16, 2020
      Member
      More actions

      I don't think that was meant to be a literal example. I think that "..." here means "and other strings".

    8. dxflores commented on Mar 16, 2020

      @dxflores
      dxfloresmannequin
      on Mar 16, 2020
      MannequinAuthor
      More actions

      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

    9. terryjreedy commented on Mar 20, 2020

      @terryjreedy
      terryjreedy
      on Mar 20, 2020
      Member
      More actions

      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.

    10. terryjreedy
      added
      3.7 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      on Mar 20, 2020
    11. terryjreedy
      changed the title [-]Error on documentation - Quick fix.[/-] [+]Error in functional how-to example[/+] on Mar 20, 2020
    12. terryjreedy
      added
      3.7 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      on Mar 20, 2020
    13. 2 remaining items

    14. terryjreedy commented on Mar 20, 2020

      @terryjreedy
      terryjreedy
      on Mar 20, 2020
      Member
      More actions

      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'.

    15. iritkatriel
      added
      easy
      3.10 (EOL)end of lifeend of life
      3.11only security fixesonly security fixes
      and removed
      3.7 (EOL)end of lifeend of life
      3.8 (EOL)end of lifeend of life
      on Mar 20, 2022
    16. iritkatriel
      changed the title [-]Error in functional how-to example[/-] [+][doc] Error in functional how-to example[/+] on Mar 20, 2022
    17. iritkatriel
      added
      easy
      3.10 (EOL)end of lifeend of life
      3.11only security fixesonly security fixes
      and removed
      3.7 (EOL)end of lifeend of life
      3.8 (EOL)end of lifeend of life
      on Mar 20, 2022
    18. iritkatriel
      changed the title [-]Error in functional how-to example[/-] [+][doc] Error in functional how-to example[/+] on Mar 20, 2022
    19. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    20. iritkatriel
      closed this as completedon Jun 25, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc direasy

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402503 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.