GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-69893: Add the close() method for xml.etree.ElementTree.iterparse() iterator by serhiy-storchaka · Pull Request #114534 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jan 24, 2024 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Add the close method for ElementTree.iterparse() object #69893

📚 Documentation preview 📚: https://cpython-previews--114534.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
pythongh-69893: Add the close() method for xml.etree.ElementTree.iter…
4a2d1d8
…parse() iterator
@serhiy-storchaka
serhiy-storchaka requested review from colesbury and hugovk January 24, 2024 15:29
@bedevere-app bedevere-app Bot added the awaiting core review label Jan 24, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Jan 24, 2024
Add the close method for ElementTree.iterparse() object #69893
Closed
colesbury
colesbury reviewed Jan 24, 2024
View reviewed changes
Comment thread Lib/test/test_xml_etree.py Outdated
iterparse(SIMPLE_XMLFILE, events)
self.assertEqual(str(cm.exception), "unknown event 'bogus'")
del cm
gc_collect()

@colesbury colesbury Jan 24, 2024

Copy link
Copy Markdown
Contributor

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 the check_no_resource_warning() context manager already calls gc_collect().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Jan 24, 2024

Copy link
Copy Markdown
Member Author

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().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
Remove unnecessary gc_collect().
3f5b365
hugovk
hugovk reviewed Jan 26, 2024
View reviewed changes
Comment thread Lib/xml/etree/ElementTree.py
gen.close()

def __del__(self):
# TODO: Emit a ResourceWarning if it was not explicitly closed.

@hugovk hugovk Jan 26, 2024

Copy link
Copy Markdown
Member

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.

Any plans for when this TODO will be done? They can end up languishing for decades :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Jan 26, 2024

Copy link
Copy Markdown
Member Author

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.

When all maintained Python versions have the close() method, so you can call it without checking the version.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hugovk hugovk Jan 26, 2024

Copy link
Copy Markdown
Member

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
hugovk
hugovk approved these changes Jan 26, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Jan 26, 2024
serhiy-storchaka
serhiy-storchaka commented Jan 26, 2024
View reviewed changes
Comment thread Lib/xml/etree/ElementTree.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
Update Lib/xml/etree/ElementTree.py
e527b59
hugovk
hugovk approved these changes Jan 26, 2024
View reviewed changes

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

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.

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
serhiy-storchaka merged commit ca715e5 into python:main Feb 4, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Feb 4, 2024
@serhiy-storchaka
serhiy-storchaka deleted the etree-iterparse-close branch February 4, 2024 15:25
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
@serhiy-storchaka @aisk
pythongh-69893: Add the close() method for xml.etree.ElementTree.iter…
233e5fd
…parse() iterator (pythonGH-114534)
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
@serhiy-storchaka @fsc-eriker
pythongh-69893: Add the close() method for xml.etree.ElementTree.iter…
ba4a301
…parse() iterator (pythonGH-114534)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@colesbury colesbury colesbury left review comments
@hugovk hugovk hugovk approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@serhiy-storchaka @colesbury @hugovk
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.