Skip to content

improper use of __setitem__ in ElementTree for Python 3.1 #50814

Closed

Description

@aroberge
mannequin
BPO 6565
Nosy @aroberge, @florentx
Superseder
  • bpo-6472: Update ElementTree with upstream changes
  • Files
  • test.py: Test file showing the behaviour described.
  • 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 2010-03-11.14:57:27.228>
    created_at = <Date 2009-07-24.19:46:51.533>
    labels = ['expert-XML', 'type-bug']
    title = 'improper use of __setitem__ in ElementTree for Python 3.1'
    updated_at = <Date 2010-03-11.14:57:27.226>
    user = 'https://github.com/aroberge'

    bugs.python.org fields:

    activity = <Date 2010-03-11.14:57:27.226>
    actor = 'flox'
    assignee = 'effbot'
    closed = True
    closed_date = <Date 2010-03-11.14:57:27.228>
    closer = 'flox'
    components = ['XML']
    creation = <Date 2009-07-24.19:46:51.533>
    creator = 'aroberge'
    dependencies = []
    files = ['14560']
    hgrepos = []
    issue_num = 6565
    keywords = []
    message_count = 3.0
    messages = ['90891', '99398', '100863']
    nosy_count = 3.0
    nosy_names = ['effbot', 'aroberge', 'flox']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = '6472'
    type = 'behavior'
    url = 'https://bugs.python.org/issue6565'
    versions = ['Python 3.1', 'Python 3.2']

    Activity

    1. aroberge commented on Jul 24, 2009

      arobergemannequin
      MannequinAuthor

      I have a function to replace the content of an ElementTree Element by
      that of another one which works using Python 2 but not with Python 3.
      I get an assertion error.

      It was suggested on the Python list that the problem is that in Python 3
      slice assignments are done with __setitem__ rather than __setslice__ but
      ElementTree has not been adapted to that -- hence the title given to
      this bug.

      The function that I use to demonstrate this (with a workaround solution)
      is as follows:

      def replace_element(elem, replacement):
          '''replace the content of an ElementTree Element by that of
      another
             one.
          '''
          elem.clear()
          elem.text = replacement.text
          elem.tail = replacement.tail
          elem.tag = replacement.tag
          elem.attrib = replacement.attrib
          try:
              elem[:] = replacement[:]  # works with Python 2.5 but not 3.1
          except AssertionError:
              del elem[:]
              for child in replacement:
                  elem.append(child)

      I have included a small test file which demonstrate the behaviour.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jul 24, 2009
    3. florentx commented on Feb 16, 2010

      florentxmannequin
      Mannequin

      Should be fixed with the upstream version, proposed on bpo-6472.

    4. added and removed
      stdlibStandard Library Python modules in the Lib/ directory
      on Feb 16, 2010
    5. florentx commented on Mar 11, 2010

      florentxmannequin
      Mannequin

      Fixed in 2.7 with bpo-6472. It should be ported to 3.x later.

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

      topic-XMLtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions