bpo-39239: epoll.unregister() no longer ignores EBADF (GH-17882)

The select.epoll.unregister() method no longer ignores the EBADF
error.
diff --git a/Doc/library/select.rst b/Doc/library/select.rst
index 8f5a2ce..bb28095 100644
--- a/Doc/library/select.rst
+++ b/Doc/library/select.rst
@@ -355,6 +355,9 @@
 
    Remove a registered file descriptor from the epoll object.
 
+   .. versionchanged:: 3.9
+      The method no longer ignores the :data:`~errno.EBADF` error.
+
 
 .. method:: epoll.poll(timeout=None, maxevents=-1)
 
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index ff0fc24..46774c2 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -382,6 +382,10 @@
 * The :mod:`venv` activation scripts no longer special-case when
   ``__VENV_PROMPT__`` is set to ``""``.
 
+* The :meth:`select.epoll.unregister` method no longer ignores the
+  :data:`~errno.EBADF` error.
+  (Contributed by Victor Stinner in :issue:`39239`.)
+
 
 CPython bytecode changes
 ------------------------
diff --git a/Lib/test/test_epoll.py b/Lib/test/test_epoll.py
index 8ac0f31..10f148f 100644
--- a/Lib/test/test_epoll.py
+++ b/Lib/test/test_epoll.py
@@ -225,7 +225,10 @@
         self.assertFalse(then - now > 0.01)
 
         server.close()
-        ep.unregister(fd)
+
+        with self.assertRaises(OSError) as cm:
+            ep.unregister(fd)
+        self.assertEqual(cm.exception.errno, errno.EBADF)
 
     def test_close(self):
         open_file = open(__file__, "rb")
diff --git a/Misc/NEWS.d/next/Library/2020-01-07-01-02-44.bpo-39239.r7vecs.rst b/Misc/NEWS.d/next/Library/2020-01-07-01-02-44.bpo-39239.r7vecs.rst
new file mode 100644
index 0000000..2a1c929
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-01-07-01-02-44.bpo-39239.r7vecs.rst
@@ -0,0 +1,2 @@
+The :meth:`select.epoll.unregister` method no longer ignores the
+:data:`~errno.EBADF` error.
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 79cc1b2..7c6d7e4 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -1447,11 +1447,6 @@
          * though this argument is ignored. */
         Py_BEGIN_ALLOW_THREADS
         result = epoll_ctl(epfd, op, fd, &ev);
-        if (errno == EBADF) {
-            /* fd already closed */
-            result = 0;
-            errno = 0;
-        }
         Py_END_ALLOW_THREADS
         break;
     default: