Skip to content

Commit

Permalink
Make string formatting consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Jun 3, 2015
1 parent 8f9c507 commit 9425876
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 65 deletions.
4 changes: 2 additions & 2 deletions rq/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def use_connection(redis=None):
use of use_connection() and stacked connection contexts.
"""
assert len(_connection_stack) <= 1, \
'You should not mix Connection contexts with use_connection().'
'You should not mix Connection contexts with use_connection()'
release_local(_connection_stack)

if redis is None:
Expand All @@ -67,7 +67,7 @@ def resolve_connection(connection=None):

connection = get_current_connection()
if connection is None:
raise NoRedisConnectionException('Could not resolve a Redis connection.')
raise NoRedisConnectionException('Could not resolve a Redis connection')
return connection


Expand Down
22 changes: 11 additions & 11 deletions rq/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def unpickle(pickled_string):
try:
obj = loads(pickled_string)
except Exception as e:
raise UnpickleError('Could not unpickle.', pickled_string, e)
raise UnpickleError('Could not unpickle', pickled_string, e)
return obj


Expand Down Expand Up @@ -99,9 +99,9 @@ def create(cls, func, args=None, kwargs=None, connection=None,
kwargs = {}

if not isinstance(args, (tuple, list)):
raise TypeError('{0!r} is not a valid args list.'.format(args))
raise TypeError('{0!r} is not a valid args list'.format(args))
if not isinstance(kwargs, dict):
raise TypeError('{0!r} is not a valid kwargs dict.'.format(kwargs))
raise TypeError('{0!r} is not a valid kwargs dict'.format(kwargs))

job = cls(connection=connection)
if id is not None:
Expand All @@ -116,7 +116,7 @@ def create(cls, func, args=None, kwargs=None, connection=None,
job._instance = func.__self__
job._func_name = func.__name__
elif inspect.isfunction(func) or inspect.isbuiltin(func):
job._func_name = '%s.%s' % (func.__module__, func.__name__)
job._func_name = '{0}.{1}'.format(func.__module__, func.__name__)
elif isinstance(func, string_types):
job._func_name = as_text(func)
elif not inspect.isclass(func) and hasattr(func, '__call__'): # a callable class instance
Expand Down Expand Up @@ -212,7 +212,7 @@ def _unpickle_data(self):
def data(self):
if self._data is UNEVALUATED:
if self._func_name is UNEVALUATED:
raise ValueError('Cannot build the job data.')
raise ValueError('Cannot build the job data')

if self._instance is UNEVALUATED:
self._instance = None
Expand Down Expand Up @@ -317,7 +317,7 @@ def __init__(self, id=None, connection=None):
self.meta = {}

def __repr__(self): # noqa
return 'Job(%r, enqueued_at=%r)' % (self._id, self.enqueued_at)
return 'Job({0!r}, enqueued_at={1!r})'.format(self._id, self.enqueued_at)

# Data access
def get_id(self): # noqa
Expand All @@ -331,7 +331,7 @@ def get_id(self): # noqa
def set_id(self, value):
"""Sets a job ID for the given job."""
if not isinstance(value, string_types):
raise TypeError('id must be a string, not {0}.'.format(type(value)))
raise TypeError('id must be a string, not {0}'.format(type(value)))
self._id = value

id = property(get_id, set_id)
Expand All @@ -344,7 +344,7 @@ def key_for(cls, job_id):
@classmethod
def dependents_key_for(cls, job_id):
"""The Redis key that is used to store job hash under."""
return 'rq:job:%s:dependents' % (job_id,)
return 'rq:job:{0}:dependents'.format(job_id)

@property
def key(self):
Expand Down Expand Up @@ -393,7 +393,7 @@ def refresh(self): # noqa
key = self.key
obj = decode_redis_hash(self.connection.hgetall(key))
if len(obj) == 0:
raise NoSuchJobError('No such job: %s' % (key,))
raise NoSuchJobError('No such job: {0}'.format(key))

def to_date(date_str):
if date_str is None:
Expand Down Expand Up @@ -526,7 +526,7 @@ def get_call_string(self): # noqa
arg_list += sorted(kwargs)
args = ', '.join(arg_list)

return '%s(%s)' % (self.func_name, args)
return '{0}({1})'.format(self.func_name, args)

def cleanup(self, ttl=None, pipeline=None):
"""Prepare job for eventual deletion (if needed). This method is usually
Expand Down Expand Up @@ -565,7 +565,7 @@ def register_dependency(self, pipeline=None):
connection.sadd(Job.dependents_key_for(self._dependency_id), self.id)

def __str__(self):
return '<Job %s: %s>' % (self.id, self.description)
return '<Job {0}: {1}>'.format(self.id, self.description)

# Job equality
def __eq__(self, other): # noqa
Expand Down
22 changes: 11 additions & 11 deletions rq/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def from_queue_key(cls, queue_key, connection=None):
"""
prefix = cls.redis_queue_namespace_prefix
if not queue_key.startswith(prefix):
raise ValueError('Not a valid RQ queue key: %s' % (queue_key,))
raise ValueError('Not a valid RQ queue key: {0}'.format(queue_key))
name = queue_key[len(prefix):]
return cls(name, connection=connection)

Expand All @@ -58,7 +58,7 @@ def __init__(self, name='default', default_timeout=None, connection=None,
self.connection = resolve_connection(connection)
prefix = self.redis_queue_namespace_prefix
self.name = name
self._key = '%s%s' % (prefix, name)
self._key = '{0}{1}'.format(prefix, name)
self._default_timeout = default_timeout
self._async = async

Expand All @@ -71,7 +71,7 @@ def __len__(self):
return self.count

def __iter__(self):
yield self
yield self

@property
def key(self):
Expand Down Expand Up @@ -230,7 +230,7 @@ def enqueue(self, f, *args, **kwargs):
"""
if not isinstance(f, string_types) and f.__module__ == '__main__':
raise ValueError('Functions from the __main__ module cannot be processed '
'by workers.')
'by workers')

# Detect explicit invocations, i.e. of the form:
# q.enqueue(foo, args=(1, 2), kwargs={'a': 1}, timeout=30)
Expand All @@ -243,7 +243,7 @@ def enqueue(self, f, *args, **kwargs):
at_front = kwargs.pop('at_front', False)

if 'args' in kwargs or 'kwargs' in kwargs:
assert args == (), 'Extra positional arguments cannot be used when using explicit args and kwargs.' # noqa
assert args == (), 'Extra positional arguments cannot be used when using explicit args and kwargs' # noqa
args = kwargs.pop('args', None)
kwargs = kwargs.pop('kwargs', None)

Expand Down Expand Up @@ -314,7 +314,7 @@ def lpop(cls, queue_keys, timeout, connection=None):
connection = resolve_connection(connection)
if timeout is not None: # blocking variant
if timeout == 0:
raise ValueError('RQ does not support indefinite timeouts. Please pick a timeout value > 0.')
raise ValueError('RQ does not support indefinite timeouts. Please pick a timeout value > 0')
result = connection.blpop(queue_keys, timeout)
if result is None:
raise DequeueTimeout(timeout, queue_keys)
Expand Down Expand Up @@ -385,22 +385,22 @@ def dequeue_any(cls, queues, timeout, connection=None):
# auto-generated by the @total_ordering decorator)
def __eq__(self, other): # noqa
if not isinstance(other, Queue):
raise TypeError('Cannot compare queues to other objects.')
raise TypeError('Cannot compare queues to other objects')
return self.name == other.name

def __lt__(self, other):
if not isinstance(other, Queue):
raise TypeError('Cannot compare queues to other objects.')
raise TypeError('Cannot compare queues to other objects')
return self.name < other.name

def __hash__(self):
return hash(self.name)

def __repr__(self): # noqa
return 'Queue(%r)' % (self.name,)
return 'Queue({0!r})'.format(self.name)

def __str__(self):
return '<Queue \'%s\'>' % (self.name,)
return '<Queue {0!r}>'.format(self.name)


class FailedQueue(Queue):
Expand Down Expand Up @@ -436,7 +436,7 @@ def requeue(self, job_id):

# Delete it from the failed queue (raise an error if that failed)
if self.remove(job) == 0:
raise InvalidJobOperationError('Cannot requeue non-failed jobs.')
raise InvalidJobOperationError('Cannot requeue non-failed jobs')

job.set_status(JobStatus.QUEUED)
job.exc_info = None
Expand Down
6 changes: 3 additions & 3 deletions rq/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class StartedJobRegistry(BaseRegistry):

def __init__(self, name='default', connection=None):
super(StartedJobRegistry, self).__init__(name, connection)
self.key = 'rq:wip:%s' % name
self.key = 'rq:wip:{0}'.format(name)

def cleanup(self, timestamp=None):
"""Remove expired jobs from registry and add them to FailedQueue.
Expand Down Expand Up @@ -108,7 +108,7 @@ class FinishedJobRegistry(BaseRegistry):

def __init__(self, name='default', connection=None):
super(FinishedJobRegistry, self).__init__(name, connection)
self.key = 'rq:finished:%s' % name
self.key = 'rq:finished:{0}'.format(name)

def cleanup(self, timestamp=None):
"""Remove expired jobs from registry.
Expand All @@ -128,7 +128,7 @@ class DeferredJobRegistry(BaseRegistry):

def __init__(self, name='default', connection=None):
super(DeferredJobRegistry, self).__init__(name, connection)
self.key = 'rq:deferred:%s' % name
self.key = 'rq:deferred:{0}'.format(name)

def cleanup(self):
"""This method is only here to prevent errors because this method is
Expand Down
2 changes: 1 addition & 1 deletion rq/timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class UnixSignalDeathPenalty(BaseDeathPenalty):

def handle_death_penalty(self, signum, frame):
raise JobTimeoutException('Job exceeded maximum timeout '
'value (%d seconds).' % self._timeout)
'value ({0} seconds)'.format(self._timeout))

def setup_death_penalty(self):
"""Sets up an alarm signal and a signal handler that raises
Expand Down
Loading

0 comments on commit 9425876

Please sign in to comment.