Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Yury Selivanov
On Sat, Apr 28, 2018 at 2:07 AM Tim Peters wrote: [...] > Speaking of which, "sublocal" would be a more accurate name, and less > likely to conflict with existing code names, but after people got over > the shock to their sense of purity, they'd appreciate typing the > shorter "local" instead ;-)

Re: [Python-ideas] [Python-Dev] (name := expression) doesn't fit the narrative of PEP 20

2018-04-28 Thread Steven D'Aprano
On Sat, Apr 28, 2018 at 10:37:33AM +1000, Steven D'Aprano wrote: > On Fri, Apr 27, 2018 at 04:24:35PM -0400, Wes Turner wrote: [...] Oops, sent to the wrong list. Sorry for the noise. -- Steve ___ Python-ideas mailing list [email protected] htt

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-28 Thread Ken Hilton
Perhaps there could be a special magic method that classes could implement for such a function? I.e. something like this: class Pizza(object): diameter = 1 toppings = [] def __init__(self, diameter=1, toppings=[]): self.diameter = diameter self.t

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Paul Moore
On 28 April 2018 at 03:37, Tim Peters wrote: > Idea: introduce a "local" pseudo-function to capture the idea of > initialized names with limited scope. This looks disturbingly good to me. I say "disturbingly" because the amount of magic involved in that "function call" is pretty high, and the mo

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Steven D'Aprano
On Fri, Apr 27, 2018 at 09:37:53PM -0500, Tim Peters wrote: > A brain dump, inspired by various use cases that came up during the > binding expression discussions. > > Idea: introduce a "local" pseudo-function to capture the idea of > initialized names with limited scope. [...] Chris' PEP 572 st

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-28 Thread Steven D'Aprano
On Sat, Apr 28, 2018 at 04:33:32PM +0800, Ken Hilton wrote: > Perhaps there could be a special magic method that classes could implement > for such a function? I.e. something like this: That doesn't help for the scenario in the original motivating example, where there are no classes involved. -

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Zero Piraeus
: On 28 April 2018 at 07:07, Tim Peters wrote: > [...] For that matter, I'd be fine too with shortening it to "let". In > fact, I prefer that! Thanks :-) If you really wanted to overcome objections that this looks too much like a function, you could spell it "$". I'm not sure what I think abou

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-28 Thread Nathaniel Smith
On Fri, Apr 27, 2018 at 5:58 AM, Chris Angelico wrote: > On Fri, Apr 27, 2018 at 9:27 PM, Steven D'Aprano wrote: > I don't think this needs any specific compiler magic or making 'dp' a > reserved name, but it might well be a lot easier to write if there > were some compiler features provided to _

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-28 Thread Steven D'Aprano
On Fri, Apr 27, 2018 at 12:35:22PM -0400, Clint Hepner wrote: > I don't want to hijack the thread on a digression, but instead of bringing `` > back for > just this one purpose, it could be used as a prefix to define a candidate > pool of new keywords. > > ``debugprint(obj) # instead of ``

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-28 Thread Steven D'Aprano
On Fri, Apr 27, 2018 at 10:53:39PM +1000, Nick Coghlan wrote: > On 27 April 2018 at 21:27, Steven D'Aprano wrote: > > > Obviously dp() would have to be magic. There's no way that I know of for > > a Python function to see the source code of its own arguments. I have no > > idea what sort of deep

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-28 Thread Steven D'Aprano
On Fri, Apr 27, 2018 at 06:27:44AM -0700, Eric Fahlgren wrote: > I've had a 'dprint' in sitecustomize for years. It clones 'print' and adds > a couple of keyword parameters, 'show_stack' and 'depth', which give > control over traceback output (walks back up sys._getframe for 'depth' > entries).

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Chris Angelico
On Sat, Apr 28, 2018 at 8:22 PM, Zero Piraeus wrote: > I think I finally worked out why I have such a violent reaction to := > in the end, by the way: it's because it reminds me of Javascript's > "===" (not the meaning, but the fact that it exists). Out of morbid curiosity, why does it remind you

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Ryan Gonzalez
I have to say, this idea feels really nice to me. It's far easier to read than := and separates the assignments and the result expression nicely. Others have brought up the same problem of = vs ==. IMO a solution could be to make a requirement that the last argument is NOT an assignment. In oth

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Soni L.
On 2018-04-27 11:37 PM, Tim Peters wrote: A brain dump, inspired by various use cases that came up during the binding expression discussions. Idea: introduce a "local" pseudo-function to capture the idea of initialized names with limited scope. As an expression, it's "local" "(" argume

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-28 Thread Eric Fahlgren
On Sat, Apr 28, 2018 at 4:27 AM, Steven D'Aprano wrote: > On Fri, Apr 27, 2018 at 06:27:44AM -0700, Eric Fahlgren wrote: > > > I've had a 'dprint' in sitecustomize for years. It clones 'print' and > adds > > a couple of keyword parameters, 'show_stack' and 'depth', which give > > control over tr

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread David Mertz
>$(a=7, $(a=a+1, a*2)) I suspect you ALREADY have bash installed on your computer, you don't need Python to emulate it. On Sat, Apr 28, 2018 at 6:22 AM, Zero Piraeus wrote: > : > > On 28 April 2018 at 07:07, Tim Peters wrote: > > [...] For that matter, I'd be fine too with shortening it to

[Python-ideas] __loader__.get_source(): semantics of returning None

2018-04-28 Thread Jeroen Demeyer
The documentation of __loader__.get_source() says "Returns None if no source is available (e.g. a built-in module)." But what does "no source is available" mean precisely? It could mean either of two things: (A) I am absolutely certain that there is no source anywhere to be found. (B) I don'

Re: [Python-ideas] __loader__.get_source(): semantics of returning None

2018-04-28 Thread Paul Moore
On 28 April 2018 at 17:09, Jeroen Demeyer wrote: > The documentation of __loader__.get_source() says > > "Returns None if no source is available (e.g. a built-in module)." > > But what does "no source is available" mean precisely? It could mean either > of two things: > > (A) I am absolutely certa

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Tim Peters
[Steven D'Aprano ] > Chris' PEP 572 started off with the concept that binding expressions > would create a "sub-local" scope, below function locals. After some > debate on Python-Ideas, Chris, Nick and Guido took the discussion off > list and decided to drop the sub-local scope idea as confusing an

Re: [Python-ideas] __loader__.get_source(): semantics of returning None

2018-04-28 Thread Jeroen Demeyer
On 2018-04-28 18:26, Paul Moore wrote: """ If a file named filename is not found, the function will look for it in the module search path, sys.path, after first checking for a PEP 302 __loader__ in module_globals, in case the module was imported from a zipfile or other non-filesystem import sourc

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Chris Angelico
On Sat, Apr 28, 2018 at 12:37 PM, Tim Peters wrote: > This is one that little else really handled nicely: > > r1, r2 = local(D = b**2 - 4*a*c, >sqrtD = math.sqrt(D), >twoa = 2*a, >((-b + sqrtD)/twoa, (-b - sqrtD)/twoa)) > > Everyone's favorite: > > i

Re: [Python-ideas] __loader__.get_source(): semantics of returning None

2018-04-28 Thread Paul Moore
On 28 April 2018 at 18:20, Jeroen Demeyer wrote: > On 2018-04-28 18:26, Paul Moore wrote: >> >> """ >> If a file named filename is not found, the function will look for it >> in the module search path, sys.path, after first checking for a PEP >> 302 __loader__ in module_globals, in case the module

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Ed Kellett
On 2018-04-28 18:36, Chris Angelico wrote: > This makes reasonable sense. The parentheses completely enclose the > local scope. It's compiler magic, and you cannot explain it as a > function call, but it makes intuitive sense. But the same thing inside > the if header itself would be much weirder.

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Ed Kellett
On 2018-04-28 18:16, Tim Peters wrote: > [Steven D'Aprano ] >> But the biggest problem is that this re-introduces exactly the same >> awful C mistake that := was chosen to avoid. Which of the following two >> contains the typo? >> >> local(spam=expression, eggs=expression, cheese = spam+eggs) >

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Chris Angelico
On Sun, Apr 29, 2018 at 6:04 AM, Ed Kellett wrote: > On 2018-04-28 18:36, Chris Angelico wrote: >> This makes reasonable sense. The parentheses completely enclose the >> local scope. It's compiler magic, and you cannot explain it as a >> function call, but it makes intuitive sense. But the same th

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Tim Peters
[Ed Kellett ] > How about if you just can't have an expression in a local()? See the quadratic equation example in the original post. When working with expressions, the entire point of the construct is to define (sub)local names for use in a result expression. > There are a few obvious alternat

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Ed Kellett
On 2018-04-28 21:40, Tim Peters wrote: > [Ed Kellett ] >> How about if you just can't have an expression in a local()? > > See the quadratic equation example in the original post. When > working with expressions, the entire point of the construct is to > define (sub)local names for use in a res

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Tim Peters
[Chris Angelico ] > I'm concerned that there are, in effect, two quite different uses of > the exact same syntax. Yes, the construct implements a profoundly different meaning of "scope" depending on the context it appears in. > 1) In an arbitrary expression, local() creates a scope that is define

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Tim Delaney
​​ On Sat, 28 Apr 2018 at 12:41, Tim Peters wrote: My big concern here involves the: ​​if local(m = re.match(regexp, line)): print(m.group(0)) example. The entire block needs to be implicitly local for that to work - what happens if I assign a new name in that block? Also, what happens with

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Steven D'Aprano
On Sun, Apr 29, 2018 at 06:20:14AM +1000, Chris Angelico wrote: > On Sun, Apr 29, 2018 at 6:04 AM, Ed Kellett wrote: > > What if the names persist until the end of the statement? [...] > Oh, you mean exactly like PEP 572 used to advocate for? :) Indeed. It was a bad idea in revision 1 and it rem

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Tim Peters
[Tim Delaney ] > My big concern here involves the: > > if local(m = re.match(regexp, line)): > print(m.group(0)) > > example. The entire block needs to be implicitly local for that to work - > what happens if I assign a new name in that block? I really don't know what you're asking there. Can

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread C Anthony Risinger
let[x](EXPR) x == EXPR let[x](a=1) x == 1 let[x](a=1, EXPR) x == EXPR let[x, y](a=1, EXPR) x == 1 y == EXPR let[x, y](a=1, b=2, EXPR) x == 2 y == EXPR z = let[x, y](a=1, EXPR) x == 1 y == EXPR z == (1, EXPR) Anybody seeing how the above might be useful, and address some of the concerns I've

Re: [Python-ideas] Allow multiple imports from a package while preserving its namespace

2018-04-28 Thread Greg Ewing
Nick Coghlan wrote: I find the imports at the top of the file to be a nice catalog of external dependencies. Not only is it useful for human readers, it's also useful for packaging tools such as py2exe that need to know which modules are being used. I experimented once with auto-importing in P

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Greg Ewing
Tim Peters wrote: To the compiler, it's approximately nothing like "a function call". It's nothing like a function call to the user, either, except in the most superficial of ways. - The explicit parentheses make it impossible to misunderstand where the expression begins or ends. Except t

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Tim Peters
To all of the following, I was talking about the syntax. Which includes that all existing Python-aware editors and IDEs already know how to format it intelligibly. It would be nice if they also colored "local" (or "let") as a keyword, though. For the rest, of course I'm already aware of the _sem

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-28 Thread Greg Ewing
Nathaniel Smith wrote: Traceback (most recent call last):   File "/tmp/blah.py", line 16, in     print(foo())           ^   File "/tmp/blah.py", line 6, in foo but he sent it in HTML using a proportional font, which spoils the effect! -- Greg

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Ken Hilton
> local { m = re.match(regexp, line) >if m: >print(m.group(0)) > } Or how about making "local" a pseudo-statement of sorts? local (m=re.match(exp, string)) { if m: print(m.group(0)) } The grammar would be as follows: local_stmt

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Steven D'Aprano
On Sat, Apr 28, 2018 at 12:16:16PM -0500, Tim Peters wrote: > [Steven D'Aprano ] > > Chris' PEP 572 started off with the concept that binding expressions > > would create a "sub-local" scope, below function locals. After some > > debate on Python-Ideas, Chris, Nick and Guido took the discussion off

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Ryan Gonzalez
I'm pretty sure the debate about braces defining scope in Python has long-since ended... -- Ryan (ライアン) Yoko Shimomura, ryo (supercell/EGOIST), Hiroyuki Sawano >> everyone else https://refi64.com/ On April 28, 2018 9:37:57 PM Ken Hilton wrote: > local { m = re.match(regexp, line)

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-28 Thread Nathaniel Smith
On Sat, Apr 28, 2018 at 7:29 PM, Greg Ewing wrote: > but he sent it in HTML using a proportional font, which spoils the effect! Uh...? https://vorpus.org/~njs/tmp/monospace.png It looks like my client used "font-family: monospace", maybe yours only understands or something? Anyway, if anyone el

[Python-ideas] Sublocal scoping at its simplest

2018-04-28 Thread Chris Angelico
There's been a lot of talk about sublocal scopes, within and without the context of PEP 572. I'd like to propose what I believe is the simplest form of sublocal scopes, and use it to simplify one specific special case in Python. There are no syntactic changes, and only a very slight semantic chang

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Chris Angelico
On Sun, Apr 29, 2018 at 12:50 PM, Steven D'Aprano wrote: > On Sat, Apr 28, 2018 at 12:16:16PM -0500, Tim Peters wrote: >> [Steven D'Aprano ] >> > Chris' PEP 572 started off with the concept that binding expressions >> > would create a "sub-local" scope, below function locals. After some >> > debat

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Tim Peters
[Tim] >> Enormously harder to implement than binding expressions, and the >> latter (to my eyes) capture many high-value use cases "good enough". [Steven D'Aprano ] > And yet you're suggesting an alternative which is harder and more > confusing. I am? I said at the start that it was a "brain dum

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Steve Barnes
On 28/04/2018 04:34, Yury Selivanov wrote: > Hi Tim, > > This is interesting. Even "as is" I prefer this to PEP 572. Below are some > comments and a slightly different idea inspired by yours (sorry!) > > On Fri, Apr 27, 2018 at 10:41 PM Tim Peters wrote: > [..] >> As an expression, it's > >>

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Greg Ewing
Tim Peters wrote: The points to using function-call-like syntax were already covered ("nothing syntactically new to learn there", The trouble is that one usually expects "nothing syntactically new" to imply "nothing semantically new" as well, which is very far from the case here. So I think tha

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Tim Delaney
On Sun, 29 Apr 2018 at 10:30, Tim Peters wrote: > [Tim Delaney ] > > My big concern here involves the: > > > ​​ > > if local(m = re.match(regexp, line)): > > print(m.group(0)) > > > > example. The entire block needs to be implicitly local for that to work - > > what happens if I assign a new

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Greg Ewing
Tim Peters wrote: (ABC had no lexical scoping either - nor, if I recall correctly, even textual nesting of its flavor of functions). If Python hadn't allowed textual nesting either, folks might have been content to leave it that way. But having textual nesting without lexical scoping was just w

Re: [Python-ideas] Sublocal scoping at its simplest

2018-04-28 Thread Steven D'Aprano
On Sun, Apr 29, 2018 at 01:14:54PM +1000, Chris Angelico wrote: [...] > def f(): > e = 2.71828 > try: > 1/0 > except Exception as e: > print(e) > print(e) > f() > I propose to change the semantics as follows: > > 1) Bind the caught exception to a sublocal 'e' > 2

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Tim Peters
Tim] Peters wrote: >> The points to using function-call-like syntax were already covered >> ("nothing syntactically new to learn there", [Greg Ewing] [> The trouble is that one usually expects "nothing syntactically > new" to imply "nothing semantically new" as well, which is very > far from the c

Re: [Python-ideas] A "local" pseudo-function

2018-04-28 Thread Tim Peters
[Tim Delaney ] >>> My big concern here involves the: >>> >>> if local(m = re.match(regexp, line)): >>> print(m.group(0)) >>> >>> example. The entire block needs to be implicitly local for that to work >>> - >>> what happens if I assign a new name in that block? [Tim Peters] >> I really don't k