From 91f263d8e051cc2d86f702606c1d1cf5d2f2d13d Mon Sep 17 00:00:00 2001 From: Serhii Maltsev Date: Thu, 19 Mar 2015 09:48:04 +0200 Subject: [PATCH] change try/except in python2/3 compatibility to to_text() --- rq/job.py | 7 ++----- tests/test_job.py | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/rq/job.py b/rq/job.py index 5dbbcf5..782c3c7 100644 --- a/rq/job.py +++ b/rq/job.py @@ -514,16 +514,13 @@ class Job(object): if self.func_name is None: return None - # Python 2/3 compatibility - try: - arg_list = [repr(arg).decode('utf-8') for arg in self.args] - except AttributeError: - arg_list = [repr(arg) for arg in self.args] + arg_list = [as_text(repr(arg)) for arg in self.args] kwargs = ['{0}={1!r}'.format(k, v) for k, v in self.kwargs.items()] # Sort here because python 3.3 & 3.4 makes different call_string arg_list += sorted(kwargs) args = ', '.join(arg_list) + return '%s(%s)' % (self.func_name, args) def cleanup(self, ttl=None, pipeline=None): diff --git a/tests/test_job.py b/tests/test_job.py index d2e7f44..1a7d231 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -31,12 +31,12 @@ class TestJob(RQTestCase): kwargs=dict(snowman="☃", null=None), ) - try: - # Python 2 - test_string = u"myfunc(12, u'\\u2603', null=None, snowman=u'\\u2603')".decode('utf-8') - except AttributeError: + if not PY2: # Python 3 test_string = "myfunc(12, '☃', null=None, snowman='☃')" + else: + # Python 2 + test_string = u"myfunc(12, u'\\u2603', null=None, snowman=u'\\u2603')".decode('utf-8') self.assertEquals( job.description,