GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — xml.etree.ElementTree.iterparse() should emit ResourceWarning when not explicitly closed · Issue #140601 · python/cpython Closed Closed Copy link Labels stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-featureA feature request or enhancementA feature request or enhancement DescriptionFeature or enhancementProposal:DescriptionThe def __del__(self): # TODO: Emit a ResourceWarning if it was not explicitly closed. # (When the close() method will be supported in all maintained Python versions.) if close_source: source.close() The ProblemWhen
Currently, no warning is issued to alert developers of this problem. Proposed SolutionImplement the TODO by:
ExampleCurrent behavior (no warning): import xml.etree.ElementTree as ET # This leaks a file handle but gives no warning context = ET.iterparse('data.xml') next(context) # Iterator goes out of scope without close() Expected behavior (with fix): import xml.etree.ElementTree as ET # This should emit ResourceWarning context = ET.iterparse('data.xml') next(context) # ResourceWarning: unclosed file <_io.BufferedReader name='data.xml'> # Proper usage (no warning): context = ET.iterparse('data.xml') next(context) context.close() # Explicit close Has this already been discussed elsewhere?This is a minor feature, which does not need previous discussion elsewhere Links to previous discussion of this feature:No response Linked PRsActivity
MetadataMetadataAssigneesLabelsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-featureA feature request or enhancementA feature request or enhancement ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| 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. |