homepage

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.

classification
Title: _elementtree problem deleting slices with steps != +1
Type: behavior Stage: resolved
Components: Library (Lib), XML Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eli.bendersky Nosy List: effbot, eli.bendersky, ezio.melotti, flox, python-dev, scoder
Priority: normal Keywords: patch

Created on 2012年03月02日 16:36 by scoder, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue14178.1.patch eli.bendersky, 2012年03月06日 04:53 review
Messages (6)
msg154780 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2012年03月02日 16:36
These are tests from lxml's ET compatibility test suite that now fail in ElementTree:
 def test_delslice_step(self):
 Element = self.etree.Element
 SubElement = self.etree.SubElement
 a = Element('a')
 b = SubElement(a, 'b')
 c = SubElement(a, 'c')
 d = SubElement(a, 'd')
 e = SubElement(a, 'e')
 del a[1::2]
 self.assertEquals(
 [b, d],
 list(a))
 def test_delslice_step_negative(self):
 Element = self.etree.Element
 SubElement = self.etree.SubElement
 a = Element('a')
 b = SubElement(a, 'b')
 c = SubElement(a, 'c')
 d = SubElement(a, 'd')
 e = SubElement(a, 'e')
 del a[::-1]
 self.assertEquals(
 [],
 list(a))
 def test_delslice_step_negative2(self):
 Element = self.etree.Element
 SubElement = self.etree.SubElement
 a = Element('a')
 b = SubElement(a, 'b')
 c = SubElement(a, 'c')
 d = SubElement(a, 'd')
 e = SubElement(a, 'e')
 del a[::-2]
 self.assertEquals(
 [b, d],
 list(a))
The error messages go like this:
 del a[1::2]
 ValueError: attempt to assign sequence of size 0 to extended slice of size 2
 del a[::-1]
 ValueError: attempt to assign sequence of size 0 to extended slice of size 4
 del a[::-2]
 ValueError: attempt to assign sequence of size 0 to extended slice of size 2
Additionally, I get this error:
 self.assertNotEquals(None, e.code)
 AttributeError: 'ParseError' object has no attribute 'code'
for this test:
 required_versions_ET['test_feed_parser_error_position'] = (1,3)
 def test_feed_parser_error_position(self):
 ParseError = self.etree.ParseError
 parser = self.etree.XMLParser()
 try:
 parser.close()
 except ParseError:
 e = sys.exc_info()[1]
 self.assertNotEquals(None, e.code)
 self.assertNotEquals(0, e.code)
 self.assert_(isinstance(e.position, tuple))
 self.assert_(e.position >= (0, 0))
The complete test suite is here:
https://github.com/lxml/lxml/blob/master/src/lxml/tests/test_elementtree.py 
msg154824 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2012年03月03日 05:02
I can confirm that this indeed fails for the C implementation, while succeeding for the Python implementation.
The C implementation doesn't appear to support extended slices for getting and setting items. Looking into it.
msg154825 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2012年03月03日 05:21
Correction: extended slices are supported. The problem appears to be just with 'del', because element_ass_subscr doesn't treat it specially and thinks we just want to assign a 0-len value to a non-0-len slice.
msg154998 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2012年03月06日 04:53
Attaching a patch that fixes the slice deletion problems.
The approach I've taken is follow a similar implementation in Objects/listobject.c; when a slice is deleted, it can be done efficiently by using memmove to shift whole blocks of leftover children.
Also added a new test class to test_xml_etree specifically to test slicing with Element objects and deleting slices with strange steps.
I'll leave it up for review for a couple of days before committing.
msg155000 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2012年03月06日 05:06
WRT the ParseError problem, I've opened issue #14207 for it since the problems are quite unrelated.
msg155224 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012年03月09日 11:39
New changeset 1a721b9a4039 by Eli Bendersky in branch 'default':
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
http://hg.python.org/cpython/rev/1a721b9a4039 
History
Date User Action Args
2022年04月11日 14:57:27adminsetgithub: 58386
2012年03月09日 11:41:00eli.benderskysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2012年03月09日 11:39:16python-devsetnosy: + python-dev
messages: + msg155224
2012年03月06日 05:06:38eli.benderskysetmessages: + msg155000
title: Failing tests for ElementTree -> _elementtree problem deleting slices with steps != +1
2012年03月06日 04:53:37eli.benderskysetassignee: eli.bendersky
stage: needs patch -> patch review
2012年03月06日 04:53:10eli.benderskysetfiles: + issue14178.1.patch

nosy: + effbot
messages: + msg154998

keywords: + patch
2012年03月03日 05:21:00eli.benderskysetmessages: + msg154825
2012年03月03日 05:02:17eli.benderskysetmessages: + msg154824
2012年03月02日 16:37:20ezio.melottisetnosy: + ezio.melotti, eli.bendersky, flox

stage: needs patch
2012年03月02日 16:36:22scodercreate

AltStyle によって変換されたページ (->オリジナル) /