Commit bf3f888
committed
gh-140601: Add ResourceWarning to iterparse when not closed
When iterparse() opens a file by filename and is not explicitly closed,
emit a ResourceWarning to alert developers of the resource leak.
This implements the TODO comment at line 1270 of ElementTree.py which
has been requesting this feature since the close() method was added.
- Add _closed flag to IterParseIterator to track state
- Emit ResourceWarning in __del__ if not closed
- Add comprehensive test cases
- Update existing tests to properly close iterators
Signed-off-by: Osama Abdelkader <[email protected]>1 parent b3c713a commit bf3f888
File tree
3 files changed
+99
-18
lines changed- Lib
- test
- xml/etree
- Misc/NEWS.d/next/Library
3 files changed
+99
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
692 | 692 | | |
693 | 693 | | |
694 | 694 | | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
701 | 701 | | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
706 | 707 | | |
| 708 | + | |
707 | 709 | | |
708 | 710 | | |
709 | 711 | | |
710 | 712 | | |
711 | 713 | | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
717 | 720 | | |
718 | 721 | | |
719 | 722 | | |
| |||
725 | 728 | | |
726 | 729 | | |
727 | 730 | | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
728 | 788 | | |
729 | 789 | | |
730 | 790 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1261 | 1261 | | |
1262 | 1262 | | |
1263 | 1263 | | |
| 1264 | + | |
1264 | 1265 | | |
1265 | 1266 | | |
1266 | 1267 | | |
1267 | 1268 | | |
| 1269 | + | |
1268 | 1270 | | |
1269 | 1271 | | |
1270 | | - | |
1271 | | - | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
1272 | 1284 | | |
1273 | | - | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
1274 | 1290 | | |
1275 | 1291 | | |
| 1292 | + | |
1276 | 1293 | | |
1277 | 1294 | | |
1278 | 1295 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments