✕
Skip to content

Broken code example in email module documentation #67699

Closed

Description

@bmispelon
mannequin
BPO 23511
Nosy @bitdancer, @berkerpeksag, @bmispelon
Files
  • issue23511.diff
  • issue23511_open_cm.diff
  • 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 = <Date 2015-02-25.16:16:47.323>
    created_at = <Date 2015-02-24.15:15:02.649>
    labels = ['type-feature', 'docs']
    title = 'Broken code example in email module documentation'
    updated_at = <Date 2015-02-25.16:16:47.322>
    user = 'https://github.com/bmispelon'

    bugs.python.org fields:

    activity = <Date 2015-02-25.16:16:47.322>
    actor = 'berker.peksag'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2015-02-25.16:16:47.323>
    closer = 'berker.peksag'
    components = ['Documentation']
    creation = <Date 2015-02-24.15:15:02.649>
    creator = 'bmispelon'
    dependencies = []
    files = ['38228', '38233']
    hgrepos = []
    issue_num = 23511
    keywords = ['patch']
    message_count = 7.0
    messages = ['236503', '236539', '236543', '236575', '236576', '236588', '236590']
    nosy_count = 5.0
    nosy_names = ['r.david.murray', 'docs@python', 'python-dev', 'berker.peksag', 'bmispelon']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue23511'
    versions = ['Python 3.4', 'Python 3.5']

    Activity

    1. bmispelon commented on Feb 24, 2015

      bmispelonmannequin
      MannequinAuthor

      The first code example at https://docs.python.org/3.5/library/email-examples.html throws an AttributeError because MIMEText's constructor expects a str object, not a bytes one:

      >>> # Import smtplib for the actual sending function
      ... import smtplib
      >>> 
      >>> # Import the email modules we'll need
      ... from email.mime.text import MIMEText
      >>> 
      >>> # Open a plain text file for reading.  For this example, assume that
      ... # the text file contains only ASCII characters.
      ... fp = open(textfile, 'rb')
      >>> # Create a text/plain message
      ... msg = MIMEText(fp.read())
      Traceback (most recent call last):
        File "<stdin>", line 2, in <module>
        File "/usr/lib/python3.4/email/mime/text.py", line 33, in __init__
          _text.encode('us-ascii')
      AttributeError: 'bytes' object has no attribute 'encode'
    2. bmispelon commented on Feb 24, 2015

      bmispelonmannequin
      MannequinAuthor

      Patch attached.

    3. berkerpeksag commented on Feb 24, 2015

      @berkerpeksag
      Member

      LGTM.

    4. bitdancer commented on Feb 25, 2015

      @bitdancer
      Member

      Looks like the example wasn't updated during the python3 transition.

      As long as we are changing it, we might as well make it use the file as a context manager.

    5. bmispelon commented on Feb 25, 2015

      bmispelonmannequin
      MannequinAuthor

      I wasn't sure if that was going to be out of scope or not.

      Here's an attached patch that fixes the remaining usages of open inside [Doc/includes](https://github.com/python/cpython/blob/main/Doc/includes) to always use a context manager.

    6. python-dev commented on Feb 25, 2015

      python-devmannequin
      Mannequin

      New changeset 89c6a6c2dd1f by Berker Peksag in branch '3.4':
      Issue bpo-23511: Port email-simple.py to Python 3.
      https://hg.python.org/cpython/rev/89c6a6c2dd1f

      New changeset cb911e1fb3dc by Berker Peksag in branch 'default':
      Issue bpo-23511: Port email-simple.py to Python 3.
      https://hg.python.org/cpython/rev/cb911e1fb3dc

    7. berkerpeksag commented on Feb 25, 2015

      @berkerpeksag
      Member

      Thanks for the patch, Baptiste.

    8. transferred this issue fromon Apr 10, 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

      docsDocumentation in the Doc dirtype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions