From 0170e0da2fa711b74bcfb87dbb1faf02461b5cc2 Mon Sep 17 00:00:00 2001 From: Bart van Merrienboer Date: Wed, 21 Jan 2015 12:34:52 -0500 Subject: Introduces a wrapper to create unbound methods. --- documentation/index.rst | 7 +++++++ six.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/documentation/index.rst b/documentation/index.rst index a8632e7..d838e38 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -232,6 +232,13 @@ functions and methods is the stdlib :mod:`py3:inspect` module. requires the *obj*'s class to be passed. +.. function:: create_unbound_method(func, cls) + + Return an unbound method object wrapping *func*. In Python 2, this will return + a :func:`py3:types.MethodType` object. In Python 3 unbound methods do not + exist and this wrapper will return *func*. + + .. class:: Iterator A class for making portable iterators. The intention is that it be subclassed diff --git a/six.py b/six.py index 16a26c8..00ce734 100644 --- a/six.py +++ b/six.py @@ -522,6 +522,9 @@ if PY3: create_bound_method = types.MethodType + def create_unbound_method(func, cls): + return func + Iterator = object else: def get_unbound_function(unbound): @@ -530,6 +533,9 @@ else: def create_bound_method(func, obj): return types.MethodType(func, obj, obj.__class__) + def create_unbound_method(func, cls): + return types.MethodType(func, None, cls) + class Iterator(object): def next(self): -- cgit v1.2.1