summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Cardona <remi.cardona@free.fr>2014-07-17 00:45:50 +0200
committerRémi Cardona <remi.cardona@free.fr>2014-07-17 00:45:50 +0200
commit24fd6fca2f119662ea9acc9b6f787349a7912ab1 (patch)
tree4c4fc0bc039aecd106fa2cff6a79d2f8d171e264
parent2b4e8cb6b0637a2953c8cf5cba6a5bce2b79eb2a (diff)
downloadlogilab-common-24fd6fca2f119662ea9acc9b6f787349a7912ab1.tar.gz
Only read/write func.__name__ and class.__self__
Since at least python 2.0, func_name and __name__ point to the same struct member and since 2.4, they share the exact same getter and setter. Since __name__ is the only property left in python 3.0, let's use that one. As for method.__self__, it has been available since at least python 2.0 too.
-rw-r--r--cli.py2
-rw-r--r--decorators.py1
-rw-r--r--deprecation.py2
-rw-r--r--pytest.py7
-rw-r--r--test/unittest_decorators.py3
5 files changed, 5 insertions, 10 deletions
diff --git a/cli.py b/cli.py
index a96ce17..9a8b8f5 100644
--- a/cli.py
+++ b/cli.py
@@ -196,7 +196,7 @@ class CLIHelper:
import traceback
traceback.print_exc()
print 'ERROR in help method %s'% (
- command_help_method.func_name)
+ command_help_method.__name__)
help_do_help = ("help", "help [topic|command]",
_("print help message for the given topic/command or \
diff --git a/decorators.py b/decorators.py
index e3942da..beafa20 100644
--- a/decorators.py
+++ b/decorators.py
@@ -69,7 +69,6 @@ class _SingleValueCache(object):
try:
wrapped.__doc__ = self.callable.__doc__
wrapped.__name__ = self.callable.__name__
- wrapped.func_name = self.callable.func_name
except:
pass
return wrapped
diff --git a/deprecation.py b/deprecation.py
index 02e4edb..9ceff17 100644
--- a/deprecation.py
+++ b/deprecation.py
@@ -78,7 +78,7 @@ class DeprecationManager(object):
def decorator(func):
message = reason or 'The function "%s" is deprecated'
if '%s' in message:
- message %= func.func_name
+ message %= func.__name__
def wrapped(*args, **kwargs):
self.warn(version, message, stacklevel+1)
return func(*args, **kwargs)
diff --git a/pytest.py b/pytest.py
index 0e3bfea..f94db7a 100644
--- a/pytest.py
+++ b/pytest.py
@@ -886,14 +886,13 @@ class SkipAwareTextTestRunner(unittest.TextTestRunner):
else:
if isinstance(test, testlib.TestCase):
meth = test._get_test_method()
- func = meth.im_func
- testname = '%s.%s' % (meth.im_class.__name__, func.__name__)
+ testname = '%s.%s' % (test.__name__, meth.__name__)
elif isinstance(test, types.FunctionType):
func = test
testname = func.__name__
elif isinstance(test, types.MethodType):
- func = test.im_func
- testname = '%s.%s' % (test.im_class.__name__, func.__name__)
+ cls = test.__self__.__class__
+ testname = '%s.%s' % (cls.__name__, test.__name__)
else:
return True # Not sure when this happens
if isgeneratorfunction(test) and skipgenerator:
diff --git a/test/unittest_decorators.py b/test/unittest_decorators.py
index 688d837..e97a56f 100644
--- a/test/unittest_decorators.py
+++ b/test/unittest_decorators.py
@@ -106,13 +106,10 @@ class DecoratorsTC(TestCase):
""" what's up doc ? """
self.assertEqual(Foo.foo.__doc__, """ what's up doc ? """)
self.assertEqual(Foo.foo.__name__, 'foo')
- self.assertEqual(Foo.foo.func_name, 'foo')
self.assertEqual(Foo.bar.__doc__, """ what's up doc ? """)
self.assertEqual(Foo.bar.__name__, 'bar')
- self.assertEqual(Foo.bar.func_name, 'bar')
self.assertEqual(Foo.quux.__doc__, """ what's up doc ? """)
self.assertEqual(Foo.quux.__name__, 'quux')
- self.assertEqual(Foo.quux.func_name, 'quux')
def test_cached_single_cache(self):
class Foo(object):