[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread nate lust
This is one of the exception cases in my proposal, variables used inside their own methods don't have __getself__ called when they are loaded. The proposal basically reads: class instances that are looked up with a named variable will have __getself__ invoked when the interpreter loads them, excep

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Greg Ewing
Steven D'Aprano wrote: The only risk here is if your refactoring does something silly, such as reusing a variable which overrides assignment: What if the variable is bound inside a loop? Does that count as silly? -- Greg ___ Python-ideas mailing list

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Andrew Barnert via Python-ideas
On Jun 27, 2019, at 16:18, Greg Ewing wrote: > > Andrew Barnert wrote: >> in Lisp, if you replace the setf macro, > > Okay, maybe Lisp wasn't a good example. In the presence of macros, > all bets are off. :-( But at least if you haven't redefined the > universe, local bindings in Lisp behave pre

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Greg Ewing
Sorry if this has already been answered, but if it has I missed it. From your demo: class HistoricVar: def __getself__(self): return self.var What stops the reference to 'self' here from invoking __getself__ again? -- Greg ___ Python-ide

[Python-ideas] Re: Canceling thread in python

2019-06-27 Thread Andrew Barnert via Python-ideas
On Thursday, June 27, 2019, 03:40:56 PM PDT, Yonatan Zunger wrote: > One possible approach (at a very schematic level, not thinking about impl > details yet) would be to have a function like Thread.raise(e: BaseException) > which stuffs the exception into thread-local storage, which then

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Greg Ewing
Andrew Barnert wrote: in Lisp, if you replace the setf macro, Okay, maybe Lisp wasn't a good example. In the presence of macros, all bets are off. :-( But at least if you haven't redefined the universe, local bindings in Lisp behave predictably. If you had code involving “x = 2” that stopped

[Python-ideas] Re: Canceling thread in python

2019-06-27 Thread Yonatan Zunger
Although thinking about it more, and in the context of this thread, the idea of an operation to "raise exception X in thread Y" doesn't seem unreasonable. After all, this is basically what happens to the main thread from the signal handler already; the C signal handler caches a bit that gets picked

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Greg Ewing
Yanghao Hua wrote: this one, on the other hand, is truly generic and universal. The problem is that it's *too* universal. A __getself__ method would be a sorcerer's-apprentice kind of magic that you can't escape when you don't want it. Suppose you want to inspect an object for debugging purpos

[Python-ideas] Re: Canceling thread in python

2019-06-27 Thread Andrew Barnert via Python-ideas
On Jun 27, 2019, at 13:36, Michael Foord wrote: > >> On Thu, 27 Jun 2019 at 20:53, Yonatan Zunger wrote: >> Generally, threads don't have a notion of non-cooperative thread >> termination. > That's precisely why thread cancellation in managed languages (like Python > is) raise an exception t

[Python-ideas] Re: Canceling thread in python

2019-06-27 Thread fuzzyman
Sorry for the rude tone of part of that email. Sent from my iPhone > On 27 Jun 2019, at 23:36, Michael Foord wrote: > > > >> On Thu, 27 Jun 2019 at 20:53, Yonatan Zunger wrote: >> Generally, threads don't have a notion of non-cooperative thread >> termination. This is because (unlike proces

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Andrew Barnert via Python-ideas
On Jun 27, 2019, at 08:59, nate lust wrote: > > There are two (three) important cases when I have exempt __getself__ from > being called. First is when an > object is used in methods defined within itself. This means that self can be > used when defining methods > without triggering recursive b

[Python-ideas] Re: Canceling thread in python

2019-06-27 Thread Guido van Rossum
On Thu, Jun 27, 2019 at 1:36 PM Michael Foord wrote: > > On Thu, 27 Jun 2019 at 20:53, Yonatan Zunger wrote: > >> Generally, threads don't have a notion of non-cooperative thread >> termination. This is because (unlike processes) threads share address >> spaces, and an unexpected termination of

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Ricky Teachey
> That's mostly available already! > > https://www.python.org/dev/peps/pep-0562/ > Indeed, and I've been using it! There is also the "clumsy and obscure" method of adding properties to modules discussed in PEP 549 : import sys, types class _MyModuleTyp

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Chris Angelico
On Fri, Jun 28, 2019 at 6:36 AM Steven D'Aprano wrote: > > On Fri, Jun 28, 2019 at 03:59:14AM +1000, Chris Angelico wrote: > > > > Are we talking past each other? > > > > > > > Without any magic, merely attempting to return the wrapper would cause > > it to collapse to the underlying object (by ca

[Python-ideas] Re: Canceling thread in python

2019-06-27 Thread Michael Foord
On Thu, 27 Jun 2019 at 20:53, Yonatan Zunger wrote: > Generally, threads don't have a notion of non-cooperative thread > termination. This is because (unlike processes) threads share address > spaces, and an unexpected termination of a thread can leave memory in > arbitrary and unexpected states.

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Chris Angelico
On Fri, Jun 28, 2019 at 6:17 AM Ricky Teachey wrote: > > I apologize in advance that this might be slightly off topic from the thread. > The idea I want to put forth is probably half baked, but I am wondering if > Nate's implementation might be adjusted to incorporate it, and if it might > solv

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Steven D'Aprano
On Fri, Jun 28, 2019 at 03:59:14AM +1000, Chris Angelico wrote: > > Are we talking past each other? > > > > Without any magic, merely attempting to return the wrapper would cause > it to collapse to the underlying object (by calling getself). Yeah, definitely talking past each other. Let's get

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Ricky Teachey
I apologize in advance that this might be slightly off topic from the thread. The idea I want to put forth is probably half baked, but I am wondering if Nate's implementation might be adjusted to incorporate it, and if it might solve a few of the objections. Hopefully someone hasn't already sugges

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading (was: (Re: Re: Overloading assignment concrete proposal (Re: Re: Operator as first class citizens -- like in s

2019-06-27 Thread Steven D'Aprano
On Thu, Jun 27, 2019 at 12:23:24PM -0400, nate lust wrote: > If you have a > bench mark you prefer I would be happy to run it against my changes and > mainline python 3.7 to see how they compare. Ultimately it will probably need to run against this: https://github.com/python/pyperformance for 3

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Chris Angelico
On Fri, Jun 28, 2019 at 3:55 AM Steven D'Aprano wrote: > > On Fri, Jun 28, 2019 at 02:44:28AM +1000, Chris Angelico wrote: > > > If it's ALWAYS called, then it's almost useless. The wrapper object > > will vanish the moment you attempt to do anything with it, devolving > > instantly to the result

[Python-ideas] Re: Canceling thread in python

2019-06-27 Thread Yonatan Zunger
Generally, threads don't have a notion of non-cooperative thread termination. This is because (unlike processes) threads share address spaces, and an unexpected termination of a thread can leave memory in arbitrary and unexpected states. (For example, what if one thread was holding a mutex when it

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Steven D'Aprano
On Fri, Jun 28, 2019 at 02:44:28AM +1000, Chris Angelico wrote: > If it's ALWAYS called, then it's almost useless. The wrapper object > will vanish the moment you attempt to do anything with it, devolving > instantly to the result of getself. I don't understand why it is useless. If the wrapper o

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Steven D'Aprano
On Thu, Jun 27, 2019 at 12:02:38PM -0400, David Mertz wrote: > Moreover, this new magic is entirely needless. Properties already 100% > cover the plausible need. I've been using Python since version 1.5 and I'm yet to learn a way to prevent re-binding of a simple (undotted) name: x = 1 # okay

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread David Mertz
It's always pretty easy to turn it into "code you control." Just take whatever the plan value/object is and wrapped it in a class with a '._value' attribute that holds the original. From there, as as many properties as you like, each of which had whatever side effects you wish. That side effect mig

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread David Mertz
The variables (names) 'f' and 'g' are reused every time the loop iterates. You are correct that doing an explicit 'del' within the loop would presumably prevent the magic mutation-not-binding behavior under discussion. I still don't want the behavior, but I admit that's a pretty easy way to be mor

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading (was: (Re: Re: Overloading assignment concrete proposal (Re: Re: Operator as first class citizens -- like in s

2019-06-27 Thread nate lust
Steven, You may have seen the message I posted a little while ago detailing a bit more about the proposed changes with an example of how the interpreter will handle things like __getself__. I have working code here; https://github.com/natelust/cpython/tree/cloakingVars. I worked very hard to keep a

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread nate lust
That is true when it is code that you control, but if it is the case you want to use some specialized metavar in the context of someone else's library things are a bit different. This could be something such as using something like a debugger tracing through some execution where you want to record

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Steven D'Aprano
On Thu, Jun 27, 2019 at 11:39:04PM +1000, Chris Angelico wrote: > On Thu, Jun 27, 2019 at 11:11 PM Steven D'Aprano wrote: > > I'm not convinced that this is going to change under the proposal. Since > > neither f nor s already exist, they cannot overload assignment. Unless > > something in Nate's

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Chris Angelico
On Fri, Jun 28, 2019 at 1:59 AM nate lust wrote: > d = a + b + c > print(d) > > tmp = a + b > d = getcloaked(tmp) + c > prtint(d) > > Now the behavior is the same as the first case, as getcloaked returns the > metavariable that has not been bound > to a name and so it is loaded right on the stack

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread David Mertz
Obviously many kinds of errors are possible in existing Python. My quick sample made one by passing 'data' rather than my intended 'datum'. As you mention, maybe 'process_the()' will return the wrong kind of object some or all of the time. Mostly I would expect subsequent code to throw a ValueErro

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread nate lust
There seems to be some confusion to what is going on with the __getself__ method. This is almost certainly dues to my lack of communicating things clearly. I am going to attempt to walk through what will happen in context of a code example. The important thing to keep in mind is that __getself__ is

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Steven D'Aprano
On Thu, Jun 27, 2019 at 09:55:53AM -0400, David Mertz wrote: > On Thu, Jun 27, 2019 at 9:13 AM Steven D'Aprano wrote: > > > The only risk here is if your refactoring does something silly, such as > > reusing a variable which overrides assignment: > > How would you propose to write this code with

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread nate lust
I addressed some of the concerns you were responding to in the long email I wrote last night. I introduced a change to address this, see previous email for more details. On Thu, Jun 27, 2019 at 9:41 AM Chris Angelico wrote: > On Thu, Jun 27, 2019 at 11:11 PM Steven D'Aprano > wrote: > > > > On

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread nate lust
I think in this case, it would depend on what the metavar is designed to do. If f was a metavar that took in a value, had side effects, and then presented the variable back on load (that would be the __getself__ part of the proposal) I also included built ins for working with this type of variable,

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread David Mertz
On Thu, Jun 27, 2019 at 9:13 AM Steven D'Aprano wrote: > The only risk here is if your refactoring does something silly, such as > reusing a variable which overrides assignment: > How would you propose to write this code without reusing a variable? def frobnicate(data): stuff = [] for d

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Chris Angelico
On Thu, Jun 27, 2019 at 11:11 PM Steven D'Aprano wrote: > > On Thu, Jun 27, 2019 at 12:46:58AM +1000, Chris Angelico wrote: > > > There are many things that can be implemented with dunders, yes, but > > in Python, I would expect these two functions to behave identically: > > > > def f1(x): > >

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Steven D'Aprano
On Thu, Jun 27, 2019 at 12:46:58AM +1000, Chris Angelico wrote: > There are many things that can be implemented with dunders, yes, but > in Python, I would expect these two functions to behave identically: > > def f1(x): > return frob(x).spam > > def f2(x): > f = frob(x) > s = f.spam

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread Rhodri James
On 27/06/2019 04:57, nate lust wrote: However it is a fair point, that it might not be transparent and you could end up with an exception thrown at some point. I would argue this is not much different than using any library code where you would need to understand the api, but documentation is not

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading (was: (Re: Re: Overloading assignment concrete proposal (Re: Re: Operator as first class citizens -- like in s

2019-06-27 Thread Steven D'Aprano
On Tue, Jun 25, 2019 at 03:34:03PM -0700, Ben Rudiak-Gould wrote: > On Tue, Jun 25, 2019 at 2:11 PM nate lust wrote: > >if an instance is bound to a variable name, any attempts to rebind > >that name will result in a call to the __setself__ (name negotiable) > >of the instance already bound to t