diff --git a/src/pl/plpython/expected/plpython_spi.out b/src/pl/plpython/expected/plpython_spi.out
index 8853e2540d..7dfdd0d4a7 100644
--- a/src/pl/plpython/expected/plpython_spi.out
+++ b/src/pl/plpython/expected/plpython_spi.out
@@ -319,12 +319,7 @@ assert len(res.fetch(3)) == 1
 assert len(res.fetch(3)) == 0
 assert len(res.fetch(3)) == 0
 try:
-    # use next() or __next__(), the method name changed in
-    # http://www.python.org/dev/peps/pep-3114/
-    try:
-        res.next()
-    except AttributeError:
-        res.__next__()
+    next(res)
 except StopIteration:
     pass
 else:
@@ -334,11 +329,7 @@ CREATE FUNCTION cursor_mix_next_and_fetch() RETURNS int AS $$
 res = plpy.cursor("select fname, lname from users order by fname")
 assert len(res.fetch(2)) == 2
 
-item = None
-try:
-    item = res.next()
-except AttributeError:
-    item = res.__next__()
+item = next(res)
 assert item['fname'] == 'rick'
 
 assert len(res.fetch(2)) == 1
@@ -357,10 +348,7 @@ CREATE FUNCTION next_after_close() RETURNS int AS $$
 res = plpy.cursor("select fname, lname from users")
 res.close()
 try:
-    try:
-        res.next()
-    except AttributeError:
-        res.__next__()
+    next(res)
 except ValueError:
     pass
 else:
@@ -370,10 +358,7 @@ CREATE FUNCTION cursor_fetch_next_empty() RETURNS int AS $$
 res = plpy.cursor("select fname, lname from users where false")
 assert len(res.fetch(1)) == 0
 try:
-    try:
-        res.next()
-    except AttributeError:
-        res.__next__()
+    next(res)
 except StopIteration:
     pass
 else:
diff --git a/src/pl/plpython/sql/plpython_spi.sql b/src/pl/plpython/sql/plpython_spi.sql
index fcd113acaa..a1a8b9c824 100644
--- a/src/pl/plpython/sql/plpython_spi.sql
+++ b/src/pl/plpython/sql/plpython_spi.sql
@@ -218,12 +218,7 @@ assert len(res.fetch(3)) == 1
 assert len(res.fetch(3)) == 0
 assert len(res.fetch(3)) == 0
 try:
-    # use next() or __next__(), the method name changed in
-    # http://www.python.org/dev/peps/pep-3114/
-    try:
-        res.next()
-    except AttributeError:
-        res.__next__()
+    next(res)
 except StopIteration:
     pass
 else:
@@ -234,11 +229,7 @@ CREATE FUNCTION cursor_mix_next_and_fetch() RETURNS int AS $$
 res = plpy.cursor("select fname, lname from users order by fname")
 assert len(res.fetch(2)) == 2
 
-item = None
-try:
-    item = res.next()
-except AttributeError:
-    item = res.__next__()
+item = next(res)
 assert item['fname'] == 'rick'
 
 assert len(res.fetch(2)) == 1
@@ -259,10 +250,7 @@ CREATE FUNCTION next_after_close() RETURNS int AS $$
 res = plpy.cursor("select fname, lname from users")
 res.close()
 try:
-    try:
-        res.next()
-    except AttributeError:
-        res.__next__()
+    next(res)
 except ValueError:
     pass
 else:
@@ -273,10 +261,7 @@ CREATE FUNCTION cursor_fetch_next_empty() RETURNS int AS $$
 res = plpy.cursor("select fname, lname from users where false")
 assert len(res.fetch(1)) == 0
 try:
-    try:
-        res.next()
-    except AttributeError:
-        res.__next__()
+    next(res)
 except StopIteration:
     pass
 else:
