Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Greg Ewing
Steven D'Aprano wrote: Or even the subject line of this email thread??? Sorry, crossed over discussions. But I think it's also true that the null-coalescing idea is for cases where it's not an error for something to be None. -- Greg ___ Python-ideas

Re: [Python-ideas] Query Language extension to Python

2016-11-02 Thread Pavel Velikhov
> 3 нояб. 2016 г., в 0:28, Denis Akhiyarov > написал(а): > > How does this compare to LINQ in .NET? Denis, PythonQL is very similar to LINQ actually. The syntax is a little different - more Pythonic vs SQL, the clauses can be composed arbitrarily, we have named tuples, that make nested q

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Kyle Lahnakoski
On 11/2/2016 2:30 PM, Zero Piraeus wrote: If I write something like obj.attr, the failure mode I care about is that obj has no attribute attr, rather than that obj is specifically None (or one of a defined group of somewhat Nonelike objects). I agree with this understanding. The problem wit

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Steven D'Aprano
On Thu, Nov 03, 2016 at 11:22:45AM +1300, Greg Ewing wrote: > The proposed .? syntax is designed for cases where it's *not* > an error for the object to be missing the attribute, No it is not. That is absolutely not what the syntax means. I'm sorry to single you out Greg, but have you read the

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread MRAB
On 2016-11-02 21:57, Greg Ewing wrote: MRAB wrote: target = expr1 || expr2 || expr3 target = expr1 && expr2 && expr3 except that only None would be considered falsey? Or would that be confusing? Yes, I think that borrowing an operator from C but giving it subtly different semantics w

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Steven D'Aprano
On Thu, Nov 03, 2016 at 02:17:14AM +1000, Nick Coghlan wrote: > Yeah, and so far the protocol based alternative I'm working on hasn't > been any less headache-inducing (Mark has been reviewing some early > iterations and had to draw a diagram to try to follow the proposed > control flow). Even if

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Mikhail V
On 2 November 2016 at 21:50, David Mertz wrote: > Even though I really don't want new null-coalescing operators, I really > appreciate the ternary operator in Python (or in C). > > On Wed, Nov 2, 2016 at 12:38 PM, Mikhail V wrote: >> >> result = a > b ? x : y >> >> is IMHO a syntactical herecy. S

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Steven D'Aprano
On Wed, Nov 02, 2016 at 08:46:54AM -0700, Guido van Rossum wrote: > But first we need to agree on what even the right definition > of ?. is. It's been frighteningly difficult to explain this even on this > list, even though I have a very clear view in my head, This is Python-Ideas and with respe

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Greg Ewing
MRAB wrote: target = expr1 || expr2 || expr3 target = expr1 && expr2 && expr3 except that only None would be considered falsey? Or would that be confusing? Yes, I think that borrowing an operator from C but giving it subtly different semantics would be *very* confusing, especially to

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Pavol Lisy
On 10/31/16, Guido van Rossum wrote: > For "everything to the right" it would seem we have some freedom: e.g. if > we have "foo.bar?.baz(bletch)" is the call included? The answer is yes -- > the concept we're after here is named "trailer" in the Grammar file in the > source code ( > https://githu

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Matt Gilson
I actually think that Zero's point here is quite valid... At some earlier point in the thread, I believe that Nick Coughlin was saying that we should be asking ourselves _why_ we want to do something like this and the result of that discussion was because there is pain when working with "pseudo-str

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Pavol Lisy
On 10/15/16, Nick Coghlan wrote: > * None-coalescing operator: x ?or y > * None-severing operator: x ?and y > * None-coalescing augmented assignment: x ?= y > * None-severing attribute access: x?.attr > * None-severing subscript lookup: x?[expr] Please don't be too harsh to me for my next words!

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Greg Ewing
Zero Piraeus writes: If I write something like obj.attr, the failure mode I care about is that obj has no attribute attr, rather than that obj is specifically None (or one of a defined group of somewhat Nonelike objects). Clearly, in such a circumstance, obj is not what I ex

Re: [Python-ideas] More user-friendly version for string.translate()

2016-11-02 Thread Chris Barker
On Wed, Nov 2, 2016 at 12:02 PM, Mikhail V wrote: > Actually even with ASCII (read for python 2.7) I would also be happy > to have such function: say I just want to keep only digits so I write: > > digits = "0123456789" > newstring = somestring.keep(digits) > well, with ascii, it's not too hard

Re: [Python-ideas] Small improvements to the profile/cProfile API

2016-11-02 Thread Tim Mitchell
Hi Ben, Mostly I just print to stdout, I imagine more flexibility would be needed in general. This is for python 2.7 - don't know if it works for 3. def profile(sort='time', restriction=(), callers=None, callees=None, filename=None): def _profileDecorator(func): "print profile stats

Re: [Python-ideas] Small improvements to the profile/cProfile API

2016-11-02 Thread Ben Hoyt
Okay, got it, that sounds fair enough. With your @profile decorator how do you tell it when and where to print the output? Can you post the source for your decorator? On Wed, Nov 2, 2016 at 4:52 PM, Tim Mitchell wrote: > I use an @profile() decorator for almost all my profiling. If you want to

Re: [Python-ideas] Small improvements to the profile/cProfile API

2016-11-02 Thread Tim Mitchell
I use an @profile() decorator for almost all my profiling. If you want to profile function foo you just decorate it and re-run the program. With a with block you have to find the places where foo is called and put with statements around the calls. I think both approaches are equally valid and usef

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread David Mertz
Even though I really don't want new null-coalescing operators, I really appreciate the ternary operator in Python (or in C). On Wed, Nov 2, 2016 at 12:38 PM, Mikhail V wrote: > result = a > b ? x : y > > is IMHO a syntactical herecy. Such things disgust me from programming. > Why on earth one ca

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Mark E. Haase
Zero Piraeus writes: > If I write something like obj.attr, the failure mode I care about is that > obj has no attribute attr, rather than that obj is specifically None (or > one of a defined group of somewhat Nonelike objects). > > Clearly, in such a circumstance, obj is not what I expected it to

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Ethan Furman
On 11/02/2016 12:32 PM, Nikolaus Rath wrote: On Nov 02 2016, Zero Piraeus wrote: On Wed, 2016-11-02 at 08:46 -0700, Guido van Rossum wrote: [...] we need to agree on what even the right definition of ?. is. It's been frighteningly difficult to explain this even on this list, even though I hav

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Nikolaus Rath
On Nov 02 2016, Zero Piraeus wrote: > On Wed, 2016-11-02 at 08:46 -0700, Guido van Rossum wrote: >> [...] we need to agree on what even the right definition of ?. is. It's >> been frighteningly difficult to explain this even on this list, even >> though I have a very clear view in my head, and PE

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Mikhail V
On 2 November 2016 at 19:34, MRAB wrote: > How about borrowing from C: > > target = expr1 || expr2 || expr3 > target = expr1 && expr2 && expr3 > > except that only None would be considered falsey? > > Or would that be confusing? Sorry for intruding into discussion and off-topic again, Su

Re: [Python-ideas] More user-friendly version for string.translate()

2016-11-02 Thread Mikhail V
On 27 October 2016 at 00:17, Chris Barker wrote: > 1) an easy way to spell "remove all the characters other than these" > > I think that's a good idea. What with unicode having an enormous number > of code points, it really does make sense to have a way to specify > only what you >want, rather tha

Re: [Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

2016-11-02 Thread Danilo J. S. Bellini
2016-10-25 12:29 GMT-02:00 Paul Moore : > On the other hand, the *ideas* are really interesting and valuable. > I'm certainly planning on looking at PyScanPrev when I get the chance. > And the discussions can frequently make people rethink their beliefs. > > So people posting ideas here should exp

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread MRAB
On 2016-11-02 16:17, Nick Coghlan wrote: [snip] Yeah, and so far the protocol based alternative I'm working on hasn't been any less headache-inducing (Mark has been reviewing some early iterations and had to draw a diagram to try to follow the proposed control flow). I think I have a way to simp

[Python-ideas] Small improvements to the profile/cProfile API

2016-11-02 Thread Ben Hoyt
Hi folks, Every time I do some Python profiling (with cProfile) the API feels kinda baroque, and I have to write ~10 line helper functions to do what I want. For example, if I want the return value of running some function and the profiling output as a string (e.g., to send as part of a web respon

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Zero Piraeus
: Disclaimer: I haven't followed all of this discussion, so some or all of the following may already have been expressed better (and perhaps refuted better still). On Wed, 2016-11-02 at 08:46 -0700, Guido van Rossum wrote: > [...] we need to agree on what even the right definition of ?. is. It's

Re: [Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

2016-11-02 Thread Danilo J. S. Bellini
2016-10-25 12:02 GMT-02:00 Stephen J. Turnbull : > My point is that although new syntax may be useful for simple cases, > serious applications will worry about computational accuracy and > likely will provide packages that handle general cases that nest these > simple cases. Given they exist, mos

Re: [Python-ideas] More user-friendly version for string.translate()

2016-11-02 Thread Chris Barker
On Tue, Nov 1, 2016 at 12:15 AM, Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > > pretty slick -- but any hope of it being as fast as a C implemented > method? > > I would expect not in CPython, but if "fast" matters, why are you > using CPython rather than PyPy or Cython?

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Sven R. Kunze
On 02.11.2016 17:17, Nick Coghlan wrote: The gist is that rather than writing the bare: target = expr1 ?? expr2 ?? expr3 You'd instead write None-coalescing as: target = exists(expr1) ?? exists(expr2) ?? expr3 and None-propagating as: target = missing(expr1) ?? missing(expr2) ??

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Nick Coghlan
On 3 November 2016 at 01:46, Guido van Rossum wrote: > But I also recall learning CoffeeScript via cargo-culting a large existing > codebase and having not the foggiest ideas when it made sense to use ?. and > when plain . was enough. So I think this feature is not very > new-user-friendly and I s

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Guido van Rossum
But I also recall learning CoffeeScript via cargo-culting a large existing codebase and having not the foggiest ideas when it made sense to use ?. and when plain . was enough. So I think this feature is not very new-user-friendly and I still expect that in the end we'll have two rejected PEPs. But

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Nick Coghlan
On 2 November 2016 at 00:46, Guido van Rossum wrote: > I personally find the ?keyword pattern has less appeal than ?, ?? or ?. . Good to know :) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Chris Angelico
On Wed, Nov 2, 2016 at 9:18 PM, Steven D'Aprano wrote: > On Wed, Nov 02, 2016 at 02:09:24PM +1100, Chris Angelico wrote: >> We already expect "to the left" and "to the right" to end based on >> operator precedence rules. Parentheses are used to control operator >> precedence. It would surprise peo

Re: [Python-ideas] Null coalescing operator

2016-11-02 Thread Steven D'Aprano
On Wed, Nov 02, 2016 at 02:09:24PM +1100, Chris Angelico wrote: > We already expect "to the left" and "to the right" to end based on > operator precedence rules. Parentheses are used to control operator > precedence. It would surprise people *greatly* if they didn't bound > the effect of the questi