pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Misprints in code
3+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2024-11-25 db80507d98  Simplify some SPI tests of PL/Python
  2024-11-25 2ff7c913d9 1a52069914 ee3415c00a ef2f4727b3  doc: Fix example with __next__() in PL/Python function
* Misprints in code
@ 2024-11-20 08:13 PG Doc comments form <noreply@postgresql.org>
  2024-11-21 15:31 ` Re: Misprints in code Erik Wienhold <ewie@ewie.name>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Doc comments form @ 2024-11-20 08:13 UTC (permalink / raw)
  To: pgsql-docs@lists.postgresql.org; +Cc: el481@yandex.ru

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/14/plpython-data.html
Description:

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)


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Misprints in code
  2024-11-20 08:13 Misprints in code PG Doc comments form <noreply@postgresql.org>
@ 2024-11-21 15:31 ` Erik Wienhold <ewie@ewie.name>
  2024-11-25 00:06   ` Re: Misprints in code Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 3+ messages in thread

From: Erik Wienhold @ 2024-11-21 15:31 UTC (permalink / raw)
  To: el481@yandex.ru; pgsql-docs@lists.postgresql.org

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

Attachments: download all (2 files, .tar.gz)

fix-plpython-docs.patch (text/x-diff, 659B) download 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; <varlistentry> <term>Iterator (any object providing <symbol>__iter__</symbol> and - <symbol>next</symbol> methods)</term> + <symbol>__next__</symbol> methods)</term> <listitem> <para> <programlisting> @@ -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
simplify-plpython-tests.patch (text/x-diff, 3.0K) download 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:
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: Misprints in code
  2024-11-20 08:13 Misprints in code PG Doc comments form <noreply@postgresql.org>
  2024-11-21 15:31 ` Re: Misprints in code Erik Wienhold <ewie@ewie.name>
@ 2024-11-25 00:06   ` Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 3+ messages in thread

From: Michael Paquier @ 2024-11-25 00:06 UTC (permalink / raw)
  To: Erik Wienhold <ewie@ewie.name>; +Cc: el481@yandex.ru; pgsql-docs@lists.postgresql.org

On Thu, Nov 21, 2024 at 04:31:07PM +0100, Erik Wienhold wrote:
> 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.

Sounds about right to me, the example greet() fails with plpython3.
For reference, this has been implemented in upstream here:
https://peps.python.org/pep-3114/

The existing tests of plpython mentioned this link, and I've bumped
over it again while looking for references on the matter.

Will fix.  Thanks for the report!
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2024-11-25 00:06 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-11-20 08:13 Misprints in code PG Doc comments form <noreply@postgresql.org>
2024-11-21 15:31 ` Erik Wienhold <ewie@ewie.name>
2024-11-25 00:06   ` Michael Paquier <michael@paquier.xyz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox