Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tE99R-005UDa-Fy for pgsql-docs@arkaria.postgresql.org; Thu, 21 Nov 2024 15:31:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tE99P-00Gole-Ii for pgsql-docs@arkaria.postgresql.org; Thu, 21 Nov 2024 15:31:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tE99P-00GolV-3g for pgsql-docs@lists.postgresql.org; Thu, 21 Nov 2024 15:31:23 +0000 Received: from mout-u-204.mailbox.org ([80.241.59.204]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tE99H-0034KE-S0 for pgsql-docs@lists.postgresql.org; Thu, 21 Nov 2024 15:31:21 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4XvMdV2W12z9tKL; Thu, 21 Nov 2024 16:31:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ewie.name; s=MBO0001; t=1732203070; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+t8bwB2LXZc9g4MEk1Dbg/WxM48C4C/ezfYi6rw6q0Q=; b=fB77IoUNkpGD7XMYszOqH/4Tz6O5SNdfbCbs406tO7wwVfidzqNkwk/1yNRNzSMkUzsUQ8 MDvPkSG5TdLhyjfLftqzFbKVDTXRiVbVF4UeAFXpv1rFGA3eX9KUuXYkSrsZMedGxDD3HN mZAR5JnMNd05n3bF8FlaDw9rfi3Kmk8FkNxzFIJRAdBAGlWGA5nY+7lqxzTK10M9Q8y8A0 DvjqCA8bzdNGd4t8LlO6BDmm/DHk6OK/U5/N78ZjrdezP1V0o+lC8CA5N+gQQqSpBQsnqC G7UDTcpVTC383Q99j1OWjCPNxfqljbpdEY1HMEt+YlbPSdaBMm9r2llQARjy/w== Date: Thu, 21 Nov 2024 16:31:07 +0100 From: Erik Wienhold To: el481@yandex.ru, pgsql-docs@lists.postgresql.org Subject: Re: Misprints in code Message-ID: References: <173209043143.2092749.13692266486972491694@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="wvmjnn5gqsxjh2ce" Content-Disposition: inline In-Reply-To: <173209043143.2092749.13692266486972491694@wrigleys.postgresql.org> X-Rspamd-Queue-Id: 4XvMdV2W12z9tKL List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --wvmjnn5gqsxjh2ce Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On 2024-11-20 09:13 +0100, PG Doc comments form wrote: > https://www.postgresql.org/docs/16/plpython-data.html#PLPYTHON-DATA-SET-RETURNING-FUNCS > The code contains a misprint in the following section: Iterator (any > object providing __iter__ and next methods) > > def next (self): must be: def __next__ (self): > > Also, the header - Iterator (any object providing __iter__ and next methods) > should be Iterator (any object providing __iter__ and __next__ methods) Good catch! That's a leftover from Python 2 and missed in commit 4228cabb72b after Python 2 was dropped in 15.0. Patch attached. While looking at, we can also simplify a couple of plpython3u test functions that still try res.next() before res.__next__(). Attached as a separate patch. -- Erik --wvmjnn5gqsxjh2ce Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="fix-plpython-docs.patch" diff --git a/doc/src/sgml/plpython.sgml b/doc/src/sgml/plpython.sgml index e5d51d6e9f..bee817ea82 100644 --- a/doc/src/sgml/plpython.sgml +++ b/doc/src/sgml/plpython.sgml @@ -553,7 +553,7 @@ $$ LANGUAGE plpython3u; Iterator (any object providing __iter__ and - next methods) + __next__ methods) @@ -569,7 +569,7 @@ AS $$ def __iter__ (self): return self - def next (self): + def __next__(self): self.ndx += 1 if self.ndx == len(self.who): raise StopIteration --wvmjnn5gqsxjh2ce Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="simplify-plpython-tests.patch" 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: --wvmjnn5gqsxjh2ce--