[issue15397] Unbinding of methods

2013-11-23 Thread Alexandre Vassalotti

Changes by Alexandre Vassalotti :


--
resolution:  -> duplicate
status: open -> closed
superseder:  -> Implement PEP 3154 (pickle protocol 4)

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-22 Thread Stefan Mihaila

Stefan Mihaila  added the comment:

Andrew, thanks for creating a separate issue (the refleak was very rare and I 
thought I'd put it in the same place, but now I realize it was a bad idea).

Richard, actually, the isinstance(self, type) check I mentioned earlier would 
have to be before the hastattr(f, '__func__') check, because Python 
classmethods provide a __func__ too:

def unbind(f):
self = getattr(f, '__self__', None)
if self is not None and not isinstance(self, types.ModuleType) \
and not isinstance(self, type):
if hasattr(f, '__func__'):
return f.__func__
return getattr(type(f.__self__), f.__name__)
raise TypeError('not a bound method')

Anyway, I'm not convinced this is worth adding anymore. As Antoine Pitrou 
suggested on the ml, it would probably be a better idea if I implemented 
__reduce__ for builtin methods as well as Python methods rather than having a 
separate opcode for pickling methods.

--

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-22 Thread Stefan Mihaila

Stefan Mihaila  added the comment:

Richard, yes, I think that would work, I didn't think of using f.__self__'s 
type.
You might want to replace
  if self is not None and not isinstance(self, types.ModuleType):
with
  if self is not None and not isinstance(self, types.ModuleType) \
  and not isinstance(self, type):
to correctly raise an exception when called on a classmethod too.

--

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-22 Thread Andrew Svetlov

Andrew Svetlov  added the comment:

Stefan, I've fixed refleak found by you in #15404. Thanks.

--

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-20 Thread Richard Oudkerk

Richard Oudkerk  added the comment:

Can't you unbind without any changes to the C code by doing

def unbind(f):
if hasattr(f, '__func__'):
return f.__func__
self = getattr(f, '__self__', None)
if self is not None and not isinstance(self, types.ModuleType):
return getattr(type(f.__self__), f.__name__)
raise TypeError('not a bound method')

Also, I am not convinced that it is a good idea to return f if f is already 
"unbound".  In practice I think you will always need to treat the bound and the 
unbound cases differently.

--
nosy: +sbt

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-20 Thread Andrew Svetlov

Andrew Svetlov  added the comment:

Stefan, you right.
A bit hairy idiom from my perspective, but it works.
Looks like this way used only for PyCFunction_New, all other code follows 
standard schema with trampoline.

--

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Stefan Mihaila

Stefan Mihaila  added the comment:

Doesn't the definition I've added at the end of methodobject.c suffice? 
(http://codereview.appspot.com/6425052/patch/1/10) Or should the macro be 
removed altogether?

--

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Martin v . Löwis

Martin v. Löwis  added the comment:

Andrew is right: PyCFunction_NewEx must stay, and must continue to get the same 
parameters as it currently does. This not only applies to extensions already 
built, but also to extensions that are built against the new header files: they 
still need to run under old Python releases (if they only use the stable ABI).

--

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Andrew Svetlov

Andrew Svetlov  added the comment:

Looks like PyCFunction_NewEx is part of Stable API.
If I'm right you have to make stub for this one as simple trampoline to new 
PyCFunction_NewExEx implementation.

Martin, please confirm.

--
nosy: +loewis

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Daniel Urban

Changes by Daniel Urban :


--
nosy: +daniel.urban

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Stefan Mihaila

Stefan Mihaila  added the comment:

Yes, the patch is at http://codereview.appspot.com/6425052/
The code there also contains some tests I've written for functools.unbind.

--
Added file: http://bugs.python.org/file26439/unbind_test.patch

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Yury Selivanov

Changes by Yury Selivanov :


--
nosy: +yselivanov

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Andrew Svetlov

Andrew Svetlov  added the comment:

Can you push patch in form available for review via Rietveld?

--

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Andrew Svetlov

Changes by Andrew Svetlov :


--
nosy: +asvetlov

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Meador Inge

Changes by Meador Inge :


--
nosy: +meador.inge
stage:  -> patch review

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Stefan Mihaila

New submission from Stefan Mihaila :

In order to implement pickling of instance methods, a means of separating
the object and the unbound method is necessary.

This is easily done for Python methods (f.__self__ and f.__func__),
but not all of builtins support __func__. Moreover, there currently
appears to be no good way to distinguish functions from bound methods.

As a first step in solving this issue, I have attached a patch which:
1) adds __func__ for all function types
2) adds a few new definitions in the types module (AllFunctionTypes etc.)
3) adds isanyfunction(), isanyboundfunction(), isanyunboundfunction() in
  inspect (admittedly these are bad names)
4) functools.unbind

In case applying this patch is being considered, serious review is necessary,
as I'm not knowledgeable of cpython internals.

--
components: Library (Lib)
files: func.patch
keywords: patch
messages: 165845
nosy: mstefanro
priority: normal
severity: normal
status: open
title: Unbinding of methods
type: enhancement
versions: Python 3.3
Added file: http://bugs.python.org/file26438/func.patch

___
Python tracker 

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



[issue15397] Unbinding of methods

2012-07-19 Thread Stefan Mihaila

Changes by Stefan Mihaila :


--
nosy: +alexandre.vassalotti, ncoghlan, rhettinger

___
Python tracker 

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