Commit 6a17574f authored by Stefan Behnel's avatar Stefan Behnel

start using f-strings (because we can :) )

parent eaa5822b
...@@ -32,7 +32,7 @@ cdef class Context(object): ...@@ -32,7 +32,7 @@ cdef class Context(object):
cdef regref(self, obj, lineno, bint is_null): cdef regref(self, obj, lineno, bint is_null):
log(LOG_ALL, u'regref', u"<NULL>" if is_null else obj, lineno) log(LOG_ALL, u'regref', u"<NULL>" if is_null else obj, lineno)
if is_null: if is_null:
self.errors.append(u"NULL argument on line %d" % lineno) self.errors.append(f"NULL argument on line {lineno}")
return return
id_ = id(obj) id_ = id(obj)
count, linenumbers = self.refs.get(id_, (0, [])) count, linenumbers = self.refs.get(id_, (0, []))
...@@ -43,13 +43,12 @@ cdef class Context(object): ...@@ -43,13 +43,12 @@ cdef class Context(object):
# returns whether it is ok to do the decref operation # returns whether it is ok to do the decref operation
log(LOG_ALL, u'delref', u"<NULL>" if is_null else obj, lineno) log(LOG_ALL, u'delref', u"<NULL>" if is_null else obj, lineno)
if is_null: if is_null:
self.errors.append(u"NULL argument on line %d" % lineno) self.errors.append(f"NULL argument on line {lineno}")
return False return False
id_ = id(obj) id_ = id(obj)
count, linenumbers = self.refs.get(id_, (0, [])) count, linenumbers = self.refs.get(id_, (0, []))
if count == 0: if count == 0:
self.errors.append(u"Too many decrefs on line %d, reference acquired on lines %r" % self.errors.append(f"Too many decrefs on line {lineno}, reference acquired on lines {linenumbers!r}")
(lineno, linenumbers))
return False return False
elif count == 1: elif count == 1:
del self.refs[id_] del self.refs[id_]
...@@ -62,7 +61,7 @@ cdef class Context(object): ...@@ -62,7 +61,7 @@ cdef class Context(object):
if self.refs: if self.refs:
msg = u"References leaked:" msg = u"References leaked:"
for count, linenos in self.refs.itervalues(): for count, linenos in self.refs.itervalues():
msg += u"\n (%d) acquired on lines: %s" % (count, u", ".join([u"%d" % x for x in linenos])) msg += f"\n ({count}) acquired on lines: {u', '.join([f'{x}' for x in linenos])}"
self.errors.append(msg) self.errors.append(msg)
if self.errors: if self.errors:
return u"\n".join([u'REFNANNY: '+error for error in self.errors]) return u"\n".join([u'REFNANNY: '+error for error in self.errors])
...@@ -74,7 +73,7 @@ cdef void report_unraisable(object e=None): ...@@ -74,7 +73,7 @@ cdef void report_unraisable(object e=None):
if e is None: if e is None:
import sys import sys
e = sys.exc_info()[1] e = sys.exc_info()[1]
print(u"refnanny raised an exception: %s" % e) print(f"refnanny raised an exception: {e}")
except: except:
pass # We absolutely cannot exit with an exception pass # We absolutely cannot exit with an exception
...@@ -161,9 +160,7 @@ cdef void FinishContext(PyObject** ctx): ...@@ -161,9 +160,7 @@ cdef void FinishContext(PyObject** ctx):
context = <Context>ctx[0] context = <Context>ctx[0]
errors = context.end() errors = context.end()
if errors: if errors:
print(u"%s: %s()" % ( print(f"{context.filename.decode('latin1')}: {context.name.decode('latin1')}()")
context.filename.decode('latin1'),
context.name.decode('latin1')))
print(errors) print(errors)
context = None context = None
except: except:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment