[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-10-04 Thread Stefan Behnel
Stefan Behnel added the comment: Closing since this works as designed. Users are responsible for avoiding concurrent tree modifications during iteration. -- resolution: -> not a bug stage: patch review -> resolved status: open -> closed ___ Pytho

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-10-04 Thread Ned Deily
Ned Deily added the comment: New changeset d5719247ba32b3ac700454bad9a9e2cc7edeac6a by Miss Skeleton (bot) in branch '3.9': bpo-41892: Clarify that an example in the ElementTree docs explicitly avoids modifying an XML tree while iterating over it. (GH-22464) (GH-22554) https://github.com/pyt

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-10-04 Thread miss-islington
miss-islington added the comment: New changeset 6bd058e0ff5d4a63fb35f6d45161cdf51cb68c58 by Miss Skeleton (bot) in branch '3.8': bpo-41892: Clarify that an example in the ElementTree docs explicitly avoids modifying an XML tree while iterating over it. (GH-22464) https://github.com/python/cp

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-10-04 Thread miss-islington
Change by miss-islington : -- pull_requests: +21552 pull_request: https://github.com/python/cpython/pull/22554 ___ Python tracker ___ __

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-10-04 Thread miss-islington
Change by miss-islington : -- nosy: +miss-islington nosy_count: 7.0 -> 8.0 pull_requests: +21551 pull_request: https://github.com/python/cpython/pull/22553 ___ Python tracker _

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-10-04 Thread Ned Deily
Ned Deily added the comment: New changeset 40db798692ca783fc2163656f196ac77e8b9e792 by scoder in branch 'master': bpo-41892: Clarify that an example in the ElementTree docs explicitly avoids modifying an XML tree while iterating over it. (GH-22464) https://github.com/python/cpython/commit/40

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-10-04 Thread Stefan Behnel
Change by Stefan Behnel : -- pull_requests: +21547 pull_request: https://github.com/python/cpython/pull/22546 ___ Python tracker ___ ___

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-10-02 Thread Stefan Behnel
Change by Stefan Behnel : -- versions: +Python 3.10, Python 3.9 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-10-01 Thread Eric V. Smith
Eric V. Smith added the comment: I can't say how ElementTree works without more checking, but this solution cannot work in general. Given a pointer to an object that's in a list, how would you get to the next item? Say the parent list-like object has a C array of pointers to the objects it c

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-10-01 Thread WoodyWoo
WoodyWoo added the comment: Could I say the mutable sequence containing not the object but the pointer like C++. So they can changed in def functions. -- ___ Python tracker _

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread WoodyWoo
WoodyWoo added the comment: @eric.smith @scoder @serhiy.storchaka Thank U all. I get what to do,and still think the "for in" structure should rebuilding. All three methods: import xml.etree.ElementTree as ET xmlstr=\ r''' 2 2008 141100

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread WoodyWoo
WoodyWoo added the comment: I think "for each in list" should not work by index,but should work by pointer like thing,could be a list of pointers. When the "for each in list" was acting,the pointers list would be fixed,and you need not to worry about the "list" changing. --

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread Stefan Behnel
Stefan Behnel added the comment: @WoodyWoo, you can (and should) do something like this: for ELEMchild in list(etroot): Modifying a container while iterating over it is usually not a good idea. The same applies to Python lists and dicts, for example. -- stage: patch review ->

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread Stefan Behnel
Change by Stefan Behnel : -- stage: -> patch review ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread Stefan Behnel
Change by Stefan Behnel : -- keywords: +patch pull_requests: +21489 stage: -> patch review pull_request: https://github.com/python/cpython/pull/22464 ___ Python tracker ___ __

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread Eric V. Smith
Eric V. Smith added the comment: The example is iterating over the list returned by root.findall(), but removing from a different data structure in root, so it won't have a problem. -- ___ Python tracker __

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread WoodyWoo
WoodyWoo added the comment: Only that makes "for each in list" literally. -- ___ Python tracker ___ ___ Python-bugs-list mailing li

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread WoodyWoo
WoodyWoo added the comment: I'm green hand in Coding. But I think the problem caused by "for each in list". Anything changed in "list" should not act at once,but should act when "for end" or break. -- ___ Python tracker

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread Eric V. Smith
Eric V. Smith added the comment: Ah, good point. I agree the example should make that clear. And I think a note in .remove() about using it while iterating would be a good idea, too. -- ___ Python tracker _

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread Stefan Behnel
Stefan Behnel added the comment: > That example is especially problematic. No, it's not. It uses .findall(), which returns a list. It's like when you make a copy of a list to iterate over, when you want to modify the original list in the loop. That could be made explicit in the text that in

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- assignee: -> docs@python components: +Documentation nosy: +docs@python, eli.bendersky, scoder ___ Python tracker ___ __

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread Eric V. Smith
Eric V. Smith added the comment: I think the only action here is to improve the documentation. That example is especially problematic. -- ___ Python tracker ___ _

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: You will get the same behavior for lists: >>> a = [1, 2, 3] >>> for x in a: ... if x == 1: ... a.remove(x) ... print(x) ... 1 3 Lists are iterated by index. First you get an item at index 0, then at index 1, etc, to the end of the list. In

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread Eric V. Smith
Eric V. Smith added the comment: I assume that ElementTree doesn't support mutation while iterating. However, the docs at https://docs.python.org/3/library/xml.etree.elementtree.html#modifying-an-xml-file show removing an item while iterating. It probably only works because the child being

[issue41892] use both "for in" and "ElementTree.remove" has a index bug

2020-09-30 Thread WoodyWoo
Change by WoodyWoo : -- title: use both "for" and "ElementTree.remove" has a index bug -> use both "for in" and "ElementTree.remove" has a index bug ___ Python tracker ___ ___