[Python-checkins] distutils2: Bring back callable.

eric.araujo python-checkins at python.org
Mon Nov 14 15:24:07 CET 2011


http://hg.python.org/distutils2/rev/18aa8ff947f4
changeset:   1236:18aa8ff947f4
user:        Éric Araujo <merwok at netwok.org>
date:        Sat Nov 12 00:42:41 2011 +0100
summary:
  Bring back callable.

hasattr is subtly wrong, as special methods are looked up on the class,
and given that the callable builtin is back in Python 3.2 we may as well
use it.  Regular users shouldn’t see the DeprecationWarnings, and us
developers can just ignore thme when running tests.

files:
  distutils2/dist.py |  7 +++----
  distutils2/run.py  |  4 ++--
  2 files changed, 5 insertions(+), 6 deletions(-)


diff --git a/distutils2/dist.py b/distutils2/dist.py
--- a/distutils2/dist.py
+++ b/distutils2/dist.py
@@ -409,13 +409,12 @@
             for help_option, short, desc, func in cmd_class.help_options:
                 if hasattr(opts, help_option.replace('-', '_')):
                     help_option_found = True
-                    if hasattr(func, '__call__'):
-                        func()
-                    else:
+                    if not callable(func):
                         raise PackagingClassError(
                             "invalid help function %r for help option %r: "
                             "must be a callable object (function, etc.)"
                             % (func, help_option))
+                    func()
 
             if help_option_found:
                 return
@@ -733,7 +732,7 @@
             else:
                 hook_obj = hook
 
-            if not hasattr(hook_obj, '__call__'):
+            if not callable(hook_obj):
                 raise PackagingOptionError('hook %r is not callable' % hook)
 
             logger.info('running %s %s for command %s',
diff --git a/distutils2/run.py b/distutils2/run.py
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -368,7 +368,7 @@
     ('list', 'List installed projects', _list),
     ('graph', 'Display a graph', _graph),
     ('create', 'Create a project', _create),
-    ('generate-setup', 'Generate a backward-comptatible setup.py', _generate),
+    ('generate-setup', 'Generate a backward-compatible setup.py', _generate),
 ]
 
 
@@ -500,7 +500,7 @@
             for help_option, short, desc, func in cmd_class.help_options:
                 if hasattr(opts, help_option.replace('-', '_')):
                     help_option_found = True
-                    if hasattr(func, '__call__'):
+                    if callable(func):
                         func()
                     else:
                         raise PackagingClassError(

-- 
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list