From 6af6fcc4c83d3cb24e96adcccdba331e62f4817a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 11 Jan 2025 13:35:45 +0200 Subject: [PATCH 1/2] gh-128731: Fix ResourceWarning in robotparser.RobotFileParser.read() --- Lib/urllib/robotparser.py | 1 + .../next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst | 1 + 2 files changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst diff --git a/Lib/urllib/robotparser.py b/Lib/urllib/robotparser.py index c58565e3945146..24ee198c355f56 100644 --- a/Lib/urllib/robotparser.py +++ b/Lib/urllib/robotparser.py @@ -65,6 +65,7 @@ def read(self): self.disallow_all = True elif err.code >= 400 and err.code < 500: self.allow_all = True + err.close() else: raw = f.read() self.parse(raw.decode("utf-8").splitlines()) diff --git a/Misc/NEWS.d/next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst b/Misc/NEWS.d/next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst new file mode 100644 index 00000000000000..81223c2efd21da --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst @@ -0,0 +1 @@ +Fix ResourceWarning in :meth:`robotparser.RobotFileParser.read`. From 2609facd9e26575faa6e0c681e56e50ba466301d Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 12 Jan 2025 12:28:32 +0200 Subject: [PATCH 2/2] Fix a reference. --- .../next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst b/Misc/NEWS.d/next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst index 81223c2efd21da..b23499ca2fea3a 100644 --- a/Misc/NEWS.d/next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst +++ b/Misc/NEWS.d/next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst @@ -1 +1 @@ -Fix ResourceWarning in :meth:`robotparser.RobotFileParser.read`. +Fix :exc:`ResourceWarning` in :meth:`urllib.robotparser.RobotFileParser.read`.