Re: Should NoneType be iterable?

2023-06-19 Thread Greg Ewing via Python-list
I would question the wisdom of designing an API that can return either a sequence or None. If it normally returns a sequence, and there are no items to return, it should return an empty sequence. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Attaching a mock function to another mock breaks reset_mock()

2023-06-19 Thread Mark Bourne via Python-list
I've came across an issue with attaching a mock function to another mock object. It looks like this might be a bug in unittest.mock, but it's possible I'm misunderstanding or doing something wrong. I'm currently using Python 3.8.10, which is the default installed on Ubuntu 20.04. I don't

Re: Bug in io.TextIOWrapper?

2023-06-19 Thread Jon Ribbens via Python-list
On 2023-06-19, Inada Naoki wrote: > I checked TextIOWrapper source code and confirmed that it doesn't call > encoder.write(text, finish=True) on close. > Since TextIOWrapper allows random access, it is difficult to call it > automatically. So please think it as just limitation rather than bug. >

Re: Should NoneType be iterable?

2023-06-19 Thread dn via Python-list
On 20/06/2023 06.12, Neal Becker via Python-list wrote: On Mon, Jun 19, 2023 at 12:42 PM Chris Angelico via Python-list < python-list@python.org> wrote: On Tue, 20 Jun 2023 at 02:37, Peter Bona via Python-list wrote: Hi I am wondering if there has been any discussion why NoneType is not

Re: Should NoneType be iterable?

2023-06-19 Thread Neal Becker via Python-list
On Mon, Jun 19, 2023 at 12:42 PM Chris Angelico via Python-list < python-list@python.org> wrote: > On Tue, 20 Jun 2023 at 02:37, Peter Bona via Python-list > wrote: > > > > Hi > > > > I am wondering if there has been any discussion why NoneType is not > iterable My feeling is that it should be.

Re: Bug in io.TextIOWrapper?

2023-06-19 Thread Inada Naoki via Python-list
I checked TextIOWrapper source code and confirmed that it doesn't call encoder.write(text, finish=True) on close. Since TextIOWrapper allows random access, it is difficult to call it automatically. So please think it as just limitation rather than bug. Please use codec and binary file manually for

Re: Bug in io.TextIOWrapper?

2023-06-19 Thread Inada Naoki via Python-list
You can use file instead of BytesIO 2023年6月20日(火) 3:05 Peter J. Holzer via Python-list : > On 2023-06-20 02:15:00 +0900, Inada Naoki via Python-list wrote: > > stream.flush() doesn't mean final output. > > Try stream.close() > > After close() the value isn't available any more: > > Python 3.11.2

Re: Bug in io.TextIOWrapper?

2023-06-19 Thread Peter J. Holzer via Python-list
On 2023-06-20 02:15:00 +0900, Inada Naoki via Python-list wrote: > stream.flush() doesn't mean final output. > Try stream.close() After close() the value isn't available any more: Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux Type "help", "copyright", "credits" or "license"

Re: Bug in io.TextIOWrapper?

2023-06-19 Thread Inada Naoki via Python-list
stream.flush() doesn't mean final output. Try stream.close() 2023年6月20日(火) 1:40 Jon Ribbens via Python-list : > io.TextIOWrapper() wraps a binary stream so you can write text to it. > It takes an 'encoding' parameter, which it uses to look up the codec > in the codecs registry, and then it uses

Bug in io.TextIOWrapper?

2023-06-19 Thread Jon Ribbens via Python-list
io.TextIOWrapper() wraps a binary stream so you can write text to it. It takes an 'encoding' parameter, which it uses to look up the codec in the codecs registry, and then it uses the IncrementalEncoder and IncrementalDecoder classes for the appropriate codec. The IncrementalEncoder.encode()

Re: Should NoneType be iterable?

2023-06-19 Thread Chris Angelico via Python-list
On Tue, 20 Jun 2023 at 02:37, Peter Bona via Python-list wrote: > > Hi > > I am wondering if there has been any discussion why NoneType is not iterable > My feeling is that it should be. > Sometimes I am using API calls which return None. > If there is a return value (which is iterable) I am

Should NoneType be iterable?

2023-06-19 Thread Peter Bona via Python-list
Hi I am wondering if there has been any discussion why NoneType is not iterable My feeling is that it should be. Sometimes I am using API calls which return None. If there is a return value (which is iterable) I am using a for loop to iterate. Now I am getting 'TypeError: 'NoneType' object is

Re: File system path annotations

2023-06-19 Thread Thomas Passin via Python-list
On 6/19/2023 10:04 AM, Roel Schroeven via Python-list wrote: Op 19/06/2023 om 11:44 schreef Peter Slížik: Thank you, Roel. You've answered all my questions. > [PEP 519]: ...as that can be represented with typing.Union[str, bytes, os.PathLike] easily enough and the hope is users > will slowly

Re: File system path annotations

2023-06-19 Thread Roel Schroeven via Python-list
Op 19/06/2023 om 11:44 schreef Peter Slížik: Thank you, Roel. You've answered all my questions. > [PEP 519]: ...as that can be represented with typing.Union[str, bytes, os.PathLike] easily enough and the hope is users > will slowly gravitate to path objects only. I read a lot on Python and,

Re: File system path annotations

2023-06-19 Thread Peter Slížik via Python-list
Thank you, Roel. You've answered all my questions. > [PEP 519]: ...as that can be represented with typing.Union[str, bytes, os.PathLike] easily enough and the hope is users > will slowly gravitate to path objects only. I read a lot on Python and, frankly, I don't see this happening. People on

Re: File system path annotations

2023-06-19 Thread Roel Schroeven via Python-list
Op 19/06/2023 om 10:43 schreef Peter Slížik via Python-list: Hello, what is the preferred way of annotating file system paths? This StackOverflow answer (and a few others) recommend using the str | os.PathLike union. However, byte arrays can be

File system path annotations

2023-06-19 Thread Peter Slížik via Python-list
Hello, what is the preferred way of annotating file system paths? This StackOverflow answer (and a few others) recommend using the str | os.PathLike union. However, byte arrays can be used as paths too, and including them would make the