https://github.com/python/cpython/commit/5e65a1acc0b630397f1d190aed279114e6e99612
commit: 5e65a1acc0b630397f1d190aed279114e6e99612
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-01-12T15:14:46+02:00
summary:

gh-128731: Fix ResourceWarning in robotparser.RobotFileParser.read() (GH-128733)

files:
A Misc/NEWS.d/next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst
M Lib/urllib/robotparser.py

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..b23499ca2fea3a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-11-13-40-12.gh-issue-128731.qpKlai.rst
@@ -0,0 +1 @@
+Fix :exc:`ResourceWarning` in :meth:`urllib.robotparser.RobotFileParser.read`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to