diff options
author | Aurelien Campeas <aurelien.campeas@logilab.fr> | 2011-09-21 18:10:25 +0200 |
---|---|---|
committer | Aurelien Campeas <aurelien.campeas@logilab.fr> | 2011-09-21 18:10:25 +0200 |
commit | 8b8a58ca17f97eda64ca7a253d3cc11893508ac1 (patch) | |
tree | 60d716007d9a3dd71d876a4303bea152ce30d858 /compat.py | |
parent | 28f99d3b81a90c73b7f5c5a7a8c2b2665fe86053 (diff) | |
download | logilab-common-8b8a58ca17f97eda64ca7a253d3cc11893508ac1.tar.gz |
fix py3k compat (closes #75290)
New:
- update compat module for callable() and method_type()
Diffstat (limited to 'compat.py')
-rw-r--r-- | compat.py | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -32,6 +32,7 @@ __docformat__ = "restructuredtext en" import os import sys +import types from warnings import warn import __builtin__ as builtins # 2to3 will tranform '__builtin__' to 'builtins' @@ -50,14 +51,22 @@ else: def str_encode(string, encoding): return str(string) -# XXX shouldn't we remove this and just let 2to3 do his job ? +# XXX callable builti-in seems back in all python versions try: - callable = callable -except NameError:# callable removed from py3k - import collections + callable = builtins.callable +except AttributeError: + from collections import Callable def callable(something): - return isinstance(something, collections.Callable) - del collections + return isinstance(something, Callable) + del Callable + +# See also http://bugs.python.org/issue11776 +if sys.version_info[0] == 3: + def method_type(callable, instance, klass): + return types.MethodType(callable, klass) +else: + # alias types otherwise + method_type = types.MethodType if sys.version_info < (3, 0): raw_input = raw_input |