[Python-ideas] Re: PEP 572: Is it a good ideas that walrus operator can be used in assertions since it causes side effects?

2020-02-12 Thread Steven D'Aprano
On Tue, Feb 11, 2020 at 07:10:18PM -, jdve...@gmail.com wrote: > I have been taught that assertions must not produce side effects at all. That's good practice, but saying that they "must not" is too strong. The risk here is not the side-effect, but relying on that side-effect (which may be

[Python-ideas] CSV Dictwriter - Handling escape characters

2020-02-12 Thread allu . matikainen
Hi, I would like if the DictWriter would be able to write escape characters (\n and \r and their combinations such as \n\n\n and \r\n) as literal characters. At the moment, DictWriter writes \n:s as new lines (shown in notepad or Excel) and I would like it to just write "\n" characters in my csv

[Python-ideas] Re: PEP 572: Is it a good ideas that walrus operator can be used in assertions since it causes side effects?

2020-02-12 Thread Ethan Furman
On 02/11/2020 01:49 PM, Steven D'Aprano wrote: Oh, definitely for the best. This now allows us to write complex assertions much more easily and efficiently: assert log(flag := complex_expression) or flag That doesn't seem very useful: for that assert to fail, `flag` would have to be fal

[Python-ideas] Re: CSV Dictwriter - Handling escape characters

2020-02-12 Thread Rhodri James
On 12/02/2020 08:15, allu.matikai...@hotmail.com wrote: Hi, I would like if the DictWriter would be able to write escape characters (\n and \r and their combinations such as \n\n\n and \r\n) as literal characters. At the moment, DictWriter writes \n:s as new lines (shown in notepad or Excel) and

[Python-ideas] Re: PEP 572: Is it a good ideas that walrus operator can be used in assertions since it causes side effects?

2020-02-12 Thread Christopher Barker
> assert log(flag := complex_expression) or flag > > That doesn't seem very useful: for that assert to fail, `flag` would have > to be falsey, and if falsey, then surely the log of it is not helpful? Unless complex_expression produces an object that has useful information when Falsey. But

[Python-ideas] Re: PEP 572: Is it a good ideas that walrus operator can be used in assertions since it causes side effects?

2020-02-12 Thread Chris Angelico
On Thu, Feb 13, 2020 at 1:50 AM Ethan Furman wrote: > > On 02/11/2020 01:49 PM, Steven D'Aprano wrote: > > > Oh, definitely for the best. This now allows us to write complex > > assertions much more easily and efficiently: > > > > assert log(flag := complex_expression) or flag > > That doesn'

[Python-ideas] Re: CSV Dictwriter - Handling escape characters

2020-02-12 Thread Andrew Barnert via Python-ideas
On Feb 12, 2020, at 06:11, allu.matikai...@hotmail.com wrote: > > I would like if the DictWriter would be able to write escape characters (\n > and \r and their combinations such as \n\n\n and \r\n) as literal characters. I don’t think you’re asking to write escape sequences, but how to write a

[Python-ideas] Re: PEP 572: Is it a good ideas that walrus operator can be used in assertions since it causes side effects?

2020-02-12 Thread Andrew Barnert via Python-ideas
On Feb 12, 2020, at 06:49, Ethan Furman wrote: > > On 02/11/2020 01:49 PM, Steven D'Aprano wrote: > >> Oh, definitely for the best. This now allows us to write complex >> assertions much more easily and efficiently: >> assert log(flag := complex_expression) or flag > > That doesn't seem ve

[Python-ideas] Re: PEP 572: Is it a good ideas that walrus operator can be used in assertions since it causes side effects?

2020-02-12 Thread Ethan Furman
On 02/12/2020 10:00 AM, Andrew Barnert wrote: On Feb 12, 2020, at 06:49, Ethan Furman wrote: On 02/11/2020 01:49 PM, Steven D'Aprano wrote: Oh, definitely for the best. This now allows us to write complex assertions much more easily and efficiently: assert log(flag := complex_expressio

[Python-ideas] Asyncio Future.set_result_threadsafe

2020-02-12 Thread Brian Allen Vanderburg II via Python-ideas
Currently asyncio.futures.Future.set_result will result in any callbacks being scheduled using loop.call_soon instead of loop.call_soon_threadsafe. However in situations where the future's result is set from a different thread, the loop might not wake up as a result of this if it is currently sleep

[Python-ideas] Re: Asyncio Future.set_result_threadsafe

2020-02-12 Thread Guido van Rossum
Sharing futures between threads like that goes counter to asyncio's basic philosophy (which is not to use threads :-). You already showed the solution: future._loop.call_soon_threadsafe(future.set_result, ...). If that's unacceptable for you, maybe you can wrap the future in a wrapper class that c