-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
gh-69893: Add the close() method for xml.etree.ElementTree.iterparse() iterator #114534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1248,10 +1248,16 @@ def iterator(source): | |
| if close_source: | ||
| source.close() | ||
|
|
||
| gen = iterator(source) | ||
| class IterParseIterator(collections.abc.Iterator): | ||
| __next__ = iterator(source).__next__ | ||
| __next__ = gen.__next__ | ||
| def close(self): | ||
| if close_source: | ||
| source.close() | ||
| gen.close() | ||
|
|
||
| def __del__(self): | ||
| # TODO: Emit a ResourceWarning if it was not explicitly closed. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any plans for when this TODO will be done? They can end up languishing for decades :)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When all maintained Python versions have the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe update the TODO to mention this, so when someone sees it they know whether they can do the TODO or wait a bit longer? Anyway, I'll approve this.
serhiy-storchaka marked this conversation as resolved.
|
||
| if close_source: | ||
| source.close() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add the :meth:`!close` method for the iterator returned by | ||
| :func:`xml.etree.ElementTree.iterparse`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added
gc_collect()calls are redundant because thecheck_no_resource_warning()context manager already callsgc_collect().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. The initial version of my patch predates
check_no_resource_warning().