[issue14369] make __closure__ writable

2017-10-11 Thread Nick Coghlan

Nick Coghlan  added the comment:

Thinking about the interaction between this idea and 
https://bugs.python.org/issue30744 made me realise that there's a subtlety here 
that would probably need to be spelled out more clearly in the docs for 
__closure__ than it is for __code__: any changes made to a function object 
(whether it's a synchronous function, a generator, or a coroutine) will only 
affect *future* function invocations, as execution frames capture references to 
both the code object and all the closure cells when they're created.

(Thought prompted by asking myself "What would happen to existing 
generator-iterators if you rebound the closure on the generator function?". The 
answer is "Nothing", but I figure if I had to think about it, that answer 
likely isn't going to be obvious to folks that are less familiar with how the 
eval loop works in practice)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2017-10-11 Thread Raymond Hettinger

Change by Raymond Hettinger :


--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2017-10-10 Thread Nick Coghlan

Nick Coghlan  added the comment:

This still seems like a reasonable enhancement, but would presumably need 
updates to apply against the 3.7 development branch.

--
versions: +Python 3.7 -Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2017-10-10 Thread Devin Bayer

Devin Bayer  added the comment:

Any updates on this? I'm trying to implement hot module reloading using code 
from IPython, which tries to modify __closure__ in place. It fails silently and 
doesn't work, but indeed would be nice to have.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2017-10-10 Thread Devin Bayer

Change by Devin Bayer :


--
nosy: +akvadrako

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-12-28 Thread Meador Inge

Changes by Meador Inge mead...@gmail.com:


--
nosy: +meador.inge

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-11-12 Thread Eric Snow

Changes by Eric Snow ericsnowcurren...@gmail.com:


--
nosy: +eric.snow

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-04-28 Thread Andrew Svetlov

Andrew Svetlov andrew.svet...@gmail.com added the comment:

sbt, looks good for me.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-04-25 Thread Richard Oudkerk

Richard Oudkerk shibt...@gmail.com added the comment:

Version of patch which checks invariants in the setter and adds tests.

--
Added file: 
http://bugs.python.org/file25363/writable_closure_with_checking.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-04-24 Thread Richard Oudkerk

Richard Oudkerk shibt...@gmail.com added the comment:

Shouldn't test___closure__() also test what happens when the closure is 
replaced with None, or a tuple which is too long or too short or contains 
non-cell objects?

All of these things seem to be checked when you create a new function using 
types.FunctionType:

 h = types.FunctionType(g.__code__, g.__globals__, h, g.__defaults__, None)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: arg 5 (closure) must be tuple
 h = types.FunctionType(g.__code__, g.__globals__, h, g.__defaults__, ())
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: g requires closure of length 2, not 0
 h = types.FunctionType(g.__code__, g.__globals__, h, g.__defaults__, 
 (1,2))
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: arg 5 (closure) expected cell, found int

I think the setter should make similar checks.  Maybe there is C code which 
assumes broken closures never happen.

--
nosy: +sbt

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-04-24 Thread Richard Oudkerk

Richard Oudkerk shibt...@gmail.com added the comment:

The patch causes crashes.  If I define

  def cell(o):
def f(): o
return f.__closure__[0]

  def f():
a = 1
b = 2
def g():
  return a + b
return g

  g = f()

then I find

  g.__closure__ = None; g()  - crash
  g.__closure__ = (cell(3),); g()- crash
  g.__closure__ = (1, 2); g()- SystemError *
  g.__closure__ = (cell(3), cell(4), cell(5)); g()   - returns 7

* SystemError: ..\Objects\cellobject.c:24: bad argument to internal function

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-04-24 Thread Yury Selivanov

Yury Selivanov yseliva...@gmail.com added the comment:

 The patch causes crashes.

Yes, that's known.  

First, we need to check, that we can only write tuple of cell objects or None 
in __closure__ (that's easy to add).  Secondly, perhaps, we can check 
__closure__ correctness each time we start evaluating a code object.  The 
latter would offer us better stability, but may also introduce some slowdowns 
-- need to find some time to implement and benchmark this.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-04-23 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

Another use case for a writeable __closure__ attribute is to make it possible 
to manually break reference cycles:
http://blog.ccpgames.com/kristjan/2012/04/23/reference-cycles-with-closures/

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-03-20 Thread Andrew Svetlov

Andrew Svetlov andrew.svet...@gmail.com added the comment:

Please update the doc also. I think changing from 'Read-only' to 'Writable' in 
Doc/reference/datamodel.rst is enough.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-03-20 Thread Yury Selivanov

Yury Selivanov yseliva...@gmail.com added the comment:

 Please update the doc also. I think changing from 'Read-only' to 'Writable' 
 in Doc/reference/datamodel.rst is enough.

Updated in writable_closure_03.patch.  Thanks.

--
Added file: http://bugs.python.org/file24962/writable_closure_03.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-03-20 Thread Andrew Svetlov

Changes by Andrew Svetlov andrew.svet...@gmail.com:


--
stage:  - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-03-20 Thread Andrew Svetlov

Changes by Andrew Svetlov andrew.svet...@gmail.com:


--
nosy: +benjamin.peterson

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-03-20 Thread Yury Selivanov

Yury Selivanov yseliva...@gmail.com added the comment:

Updated patch per Benjamin's review. See writable_closure_04.patch.

--
Added file: http://bugs.python.org/file24975/writable_closure_04.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-03-20 Thread Yury Selivanov

Changes by Yury Selivanov yseliva...@gmail.com:


--
nosy: +ncoghlan

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-03-19 Thread Yury Selivanov

New submission from Yury Selivanov yseliva...@gmail.com:

__code__ and __closure__ are designed to work together.  There is no point in 
allowing to completely substitute the __code__ object, but protecting the 
__closure__.

--
components: Interpreter Core
files: writable_closure.patch
keywords: patch
messages: 156350
nosy: Yury.Selivanov, asvetlov, pitrou
priority: normal
severity: normal
status: open
title: make __closure__ writable
type: enhancement
versions: Python 3.3
Added file: http://bugs.python.org/file24943/writable_closure.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-03-19 Thread Yury Selivanov

Changes by Yury Selivanov yseliva...@gmail.com:


Removed file: http://bugs.python.org/file24943/writable_closure.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-03-19 Thread Yury Selivanov

Changes by Yury Selivanov yseliva...@gmail.com:


Added file: http://bugs.python.org/file24946/writable_closure.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14369] make __closure__ writable

2012-03-19 Thread Yury Selivanov

Yury Selivanov yseliva...@gmail.com added the comment:

Updated patch as per Andrew's code review.  Thank you.

--
Added file: http://bugs.python.org/file24947/writable_closure_02.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com