try to call __bytes__ before __index__ (closes #16722)
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index fe6e939..f88c242 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -701,6 +701,12 @@
             def __bytes__(self):
                 return None
         self.assertRaises(TypeError, bytes, A())
+        class A:
+            def __bytes__(self):
+                return b'a'
+            def __index__(self):
+                return 42
+        self.assertEqual(bytes(A()), b'a')
 
     # Test PyBytes_FromFormat()
     def test_from_format(self):