diff options
author | Simon Feltman <sfeltman@src.gnome.org> | 2014-04-28 17:23:19 -0700 |
---|---|---|
committer | Thomas A Caswell <tcaswell@gmail.com> | 2015-09-29 15:12:41 -0400 |
commit | 750060dc0211cfb5786ba39da7283e5885eac7ad (patch) | |
tree | 28337e94a44554ecf2c8263a8068e303f814b0dc | |
parent | 06166e54cea2302bf9213f18881495eb2b5d089d (diff) | |
download | gobject-introspection-750060dc0211cfb5786ba39da7283e5885eac7ad.tar.gz |
giscanner: Replace repr format usage with string formatter
Replace occurances of "%r" (repr) in format strings where the intended
behaviour is to output a quoted string "'foo'" with explicit usage
of "'%s'". This is needed to move the codebase to unicode literals
in order to upgrade to Python 3. Python 2 unicode strings are expanded
with repr formatting prefixed with a "u" as in "u'foo'" which causes
failures for various text formatting scenarios.
https://bugzilla.gnome.org/show_bug.cgi?id=679438
-rw-r--r-- | giscanner/annotationparser.py | 8 | ||||
-rw-r--r-- | giscanner/ast.py | 6 | ||||
-rw-r--r-- | giscanner/gdumpparser.py | 4 | ||||
-rw-r--r-- | giscanner/maintransformer.py | 44 | ||||
-rw-r--r-- | giscanner/message.py | 2 | ||||
-rwxr-xr-x | giscanner/scannermain.py | 8 | ||||
-rw-r--r-- | giscanner/sourcescanner.py | 6 | ||||
-rw-r--r-- | giscanner/transformer.py | 13 | ||||
-rwxr-xr-x | misc/update-glib-annotations.py | 4 | ||||
-rw-r--r-- | tests/warn/warningtester.py | 8 |
10 files changed, 52 insertions, 51 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index 99502b28..09026a4c 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -543,7 +543,7 @@ class GtkDocAnnotatable(object): self.annotations = GtkDocAnnotations() def __repr__(self): - return '<GtkDocAnnotatable %r %r>' % (self.annotations, ) + return "<GtkDocAnnotatable '%s' %r>" % (self.annotations, ) def validate(self): ''' @@ -984,7 +984,7 @@ class GtkDocParameter(GtkDocAnnotatable): self.description = None def __repr__(self): - return '<GtkDocParameter %r %r>' % (self.name, self.annotations) + return "<GtkDocParameter '%s' %r>" % (self.name, self.annotations) class GtkDocTag(GtkDocAnnotatable): @@ -1010,7 +1010,7 @@ class GtkDocTag(GtkDocAnnotatable): self.description = None def __repr__(self): - return '<GtkDocTag %r %r>' % (self.name, self.annotations) + return "<GtkDocTag '%s' %r>" % (self.name, self.annotations) class GtkDocCommentBlock(GtkDocAnnotatable): @@ -1060,7 +1060,7 @@ class GtkDocCommentBlock(GtkDocAnnotatable): return cmp(self.name, other.name) def __repr__(self): - return '<GtkDocCommentBlock %r %r>' % (self.name, self.annotations) + return "<GtkDocCommentBlock '%s' %r>" % (self.name, self.annotations) def validate(self): ''' diff --git a/giscanner/ast.py b/giscanner/ast.py index fe1a2e57..db1f07be 100644 --- a/giscanner/ast.py +++ b/giscanner/ast.py @@ -564,7 +564,7 @@ GIName. It's possible for nodes to contain or point to other nodes.""" return cmp(self.name, other.name) def __repr__(self): - return '%s(%r)' % (self.__class__.__name__, self.name) + return "%s('%s')" % (self.__class__.__name__, self.name) def inherit_file_positions(self, node): self.file_positions.update(node.file_positions) @@ -861,7 +861,7 @@ class Member(Annotated): return cmp(self.name, other.name) def __repr__(self): - return '%s(%r)' % (self.__class__.__name__, self.name) + return "%s('%s')" % (self.__class__.__name__, self.name) class Compound(Node, Registered): @@ -934,7 +934,7 @@ class Field(Annotated): return cmp(self.name, other.name) def __repr__(self): - return '%s(%r)' % (self.__class__.__name__, self.name) + return "%s('%s')" % (self.__class__.__name__, self.name) class Record(Compound): diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py index 7b154a8e..6fcf5896 100644 --- a/giscanner/gdumpparser.py +++ b/giscanner/gdumpparser.py @@ -300,7 +300,7 @@ blob containing data gleaned from GObject's primitive introspection.""" (ns, name) = self._transformer.split_csymbol(get_type) assert ns is self._namespace if name in ('get_type', '_get_gtype'): - message.fatal("""The GObject name %r isn't compatible + message.fatal("""The GObject name '%s' isn't compatible with the configured identifier prefixes: %r The class would have no name. Most likely you want to specify a @@ -353,7 +353,7 @@ different --identifier-prefix.""" % (xmlnode.attrib['name'], self._namespace.ide if isinstance(record, ast.Record): node.ctype = record.ctype else: - message.warn_node(node, "Couldn't find associated structure for '%r'" % (node.name, )) + message.warn_node(node, "Couldn't find associated structure for '%s'" % (node.name, )) # GtkFileChooserEmbed is an example of a private interface, we # just filter them out diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 72909b34..716f6c28 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -130,7 +130,7 @@ class MainTransformer(object): origin_name = 'return value' message.log_node( message.FATAL, parent, - "can't find parameter %s referenced by %s of %r" + "can't find parameter %s referenced by %s of '%s'" % (param_name, origin_name, parent.name)) return param.argname @@ -144,7 +144,7 @@ class MainTransformer(object): origin_name = 'field %s' % (origin.name, ) message.log_node( message.FATAL, parent, - "can't find field %s referenced by %s of %r" + "can't find field %s referenced by %s of '%s'" % (field_name, origin_name, parent.name)) return field.name @@ -159,17 +159,17 @@ class MainTransformer(object): target = self._namespace.get_by_symbol(rename_to) if not target: message.warn_node(node, - "Can't find symbol %r referenced by \"rename-to\" annotation" % (rename_to, )) + "Can't find symbol '%s' referenced by \"rename-to\" annotation" % (rename_to, )) elif target.shadowed_by: message.warn_node(node, - "Function %r already shadowed by %r, can't overwrite " - "with %r" % (target.symbol, + "Function '%s' already shadowed by '%s', can't overwrite " + "with '%s'" % (target.symbol, target.shadowed_by, rename_to)) elif target.shadows: message.warn_node(node, - "Function %r already shadows %r, can't multiply shadow " - "with %r" % (target.symbol, + "Function '%s' already shadows '%s', can't multiply shadow " + "with '%s'" % (target.symbol, target.shadows, rename_to)) else: @@ -207,7 +207,7 @@ class MainTransformer(object): elif isinstance(node, ast.Registered) and node.gtype_name is not None: return node.gtype_name return node.c_name - raise AssertionError("Unhandled node %r" % (node, )) + raise AssertionError("Unhandled node '%s'" % (node, )) def _get_block(self, node): return self._blocks.get(self._get_annotation_name(node)) @@ -297,7 +297,7 @@ class MainTransformer(object): elif isinstance(base, ast.Map) and len(rest) == 2: return ast.Map(*rest) message.warn( - "Too many parameters in type specification %r" % (type_str, )) + "Too many parameters in type specification '%s'" % (type_str, )) return base def top_combiner(base, *rest): @@ -307,7 +307,7 @@ class MainTransformer(object): result, rest = grab_one(type_str, resolver, top_combiner, combiner) if rest: - message.warn("Trailing components in type specification %r" % ( + message.warn("Trailing components in type specification '%s'" % ( type_str, )) if not result.resolved: @@ -317,7 +317,7 @@ class MainTransformer(object): position = self._get_position(parent, node) else: text = type_str - message.warn_node(parent, "%s: Unknown type: %r" % + message.warn_node(parent, "%s: Unknown type: '%s'" % (text, type_str), positions=position) return result @@ -799,13 +799,13 @@ class MainTransformer(object): text = '' elif len(unused) == 1: (param, ) = unused - text = ', should be %r' % (param, ) + text = ", should be '%s'" % (param, ) else: - text = ', should be one of %s' % (', '.join(repr(p) for p in unused), ) + text = ", should be one of %s" % (', '.join("'%s'" % p for p in unused), ) param = block.params.get(doc_name) - message.warn('%s: unknown parameter %r in documentation ' - 'comment%s' % (block.name, doc_name, text), + message.warn("%s: unknown parameter '%s' in documentation " + "comment%s" % (block.name, doc_name, text), param.position) def _apply_annotations_callable(self, node, chain, block): @@ -924,7 +924,7 @@ class MainTransformer(object): break if not matched: message.warn_node(node, - "Virtual slot %r not found for %r annotation" % (invoker_name, + "Virtual slot '%s' not found for '%s' annotation" % (invoker_name, ANN_VFUNC)) return True @@ -1255,7 +1255,7 @@ method or constructor of some type.""" if func.is_constructor: message.warn_node( func, - "Can't find matching type for constructor; symbol=%r" % (func.symbol, )) + "Can't find matching type for constructor; symbol='%s'" % (func.symbol, )) return False # Some sanity checks; only objects and boxeds can have ctors @@ -1288,7 +1288,7 @@ method or constructor of some type.""" if parent is None: message.warn_node(func, "Return value is not superclass for constructor; " - "symbol=%r constructed=%r return=%r" % + "symbol='%s' constructed='%s' return='%s'" % (func.symbol, str(origin_node.create_type()), str(func.retval.type))) @@ -1296,8 +1296,8 @@ method or constructor of some type.""" else: if origin_node != target: message.warn_node(func, - "Constructor return type mismatch symbol=%r " - "constructed=%r return=%r" % + "Constructor return type mismatch symbol='%s' " + "constructed='%s' return='%s'" % (func.symbol, str(origin_node.create_type()), str(func.retval.type))) @@ -1309,8 +1309,8 @@ method or constructor of some type.""" """Look for virtual methods from the class structure.""" if not node.glib_type_struct: # https://bugzilla.gnome.org/show_bug.cgi?id=629080 - # message.warn_node(node, - # "Failed to find class structure for %r" % (node.name, )) + #message.warn_node(node, + # "Failed to find class structure for '%s'" % (node.name, )) return node_type = node.create_type() diff --git a/giscanner/message.py b/giscanner/message.py index b4321072..96cf455a 100644 --- a/giscanner/message.py +++ b/giscanner/message.py @@ -178,7 +178,7 @@ class MessageLogger(object): def log_symbol(self, log_type, symbol, text): """Log a warning in the context of the given symbol.""" self.log(log_type, text, symbol.position, - prefix="symbol=%r" % (symbol.ident, )) + prefix="symbol='%s'" % (symbol.ident, )) def log_node(log_type, node, text, context=None, positions=None): diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index b2b286f5..dd3f2b76 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -275,7 +275,7 @@ def test_codegen(optstring, include_last_src) gen.write() else: - _error("Invaild namespace %r" % (namespace, )) + _error("Invaild namespace '%s'" % (namespace, )) return 0 @@ -385,11 +385,11 @@ def create_transformer(namespace, options): for include in options.includes: if os.sep in include: - _error("Invalid include path %r" % (include, )) + _error("Invalid include path '%s'" % (include, )) try: include_obj = Include.from_string(include) except: - _error("Malformed include %r\n" % (include, )) + _error("Malformed include '%s'\n" % (include, )) transformer.register_include(include_obj) for include_path in options.includes_uninstalled: transformer.register_include_uninstalled(include_path) @@ -454,7 +454,7 @@ def write_output(data, options): with os.fdopen(temp_f, 'w') as temp_f: passthrough_gir(main_f_name, temp_f) if not utils.files_are_identical(main_f_name, temp_f_name): - _error("Failed to re-parse gir file; scanned=%r passthrough=%r" % ( + _error("Failed to re-parse gir file; scanned='%s' passthrough='%s'" % ( main_f_name, temp_f_name)) os.unlink(temp_f_name) try: diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py index b6f2dc4d..5de24ff7 100644 --- a/giscanner/sourcescanner.py +++ b/giscanner/sourcescanner.py @@ -124,7 +124,7 @@ class SourceType(object): self._stype = stype def __repr__(self): - return '<%s type=%r name=%r>' % ( + return "<%s type='%s' name='%s'>" % ( self.__class__.__name__, ctype_name(self.type), self.name) @@ -171,8 +171,8 @@ class SourceSymbol(object): if src: line = self.line if line: - src += ':%r' % (line, ) - return '<%s type=%r ident=%r src=%r>' % ( + src += ":'%s'" % (line, ) + return "<%s type='%s' ident='%s' src='%s'>" % ( self.__class__.__name__, symbol_type_name(self.type), self.ident, diff --git a/giscanner/transformer.py b/giscanner/transformer.py index 2542440a..2182182f 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -142,7 +142,7 @@ class Transformer(object): def register_include_uninstalled(self, include_path): basename = os.path.basename(include_path) if not basename.endswith('.gir'): - raise SystemExit("Include path %r must be a filename path " + raise SystemExit("Include path '%s' must be a filename path " "ending in .gir" % (include_path, )) girname = basename[:-4] include = ast.Include.from_string(girname) @@ -199,7 +199,8 @@ None.""" path = os.path.join(d, girname) if os.path.exists(path): return path - sys.stderr.write("Couldn't find include %r (search path: %r)\n" % (girname, searchdirs)) + sys.stderr.write("Couldn't find include '%s' (search path: '%s')\n" % + (girname, searchdirs)) sys.exit(1) @classmethod @@ -292,7 +293,7 @@ currently-scanned namespace is first.""" for ns in unprefixed_namespaces: if name in ns: return [(ns, name)] - raise ValueError("Unknown namespace for %s %r" + raise ValueError("Unknown namespace for %s '%s'" % ('identifier' if is_identifier else 'symbol', name, )) def split_ctype_namespaces(self, ident): @@ -340,7 +341,7 @@ raise ValueError.""" return name (ns, name) = matches[-1] raise TransformerException( - "Skipping foreign identifier %r from namespace %s" % (ident, ns.name, )) + "Skipping foreign identifier '%s' from namespace %s" % (ident, ns.name, )) return None def _strip_symbol(self, symbol): @@ -382,7 +383,7 @@ raise ValueError.""" elif stype == CSYMBOL_TYPE_OBJECT: pass else: - print('transformer: unhandled symbol: %r' % (symbol, )) + print("transformer: unhandled symbol: '%s'" % (symbol, )) def _enum_common_prefix(self, symbol): def common_prefix(a, b): @@ -615,7 +616,7 @@ raise ValueError.""" return ast.Alias(name, target, ctype=symbol.ident) else: raise NotImplementedError( - "symbol %r of type %s" % (symbol.ident, ctype_name(ctype))) + "symbol '%s' of type %s" % (symbol.ident, ctype_name(ctype))) return node def _canonicalize_ctype(self, ctype): diff --git a/misc/update-glib-annotations.py b/misc/update-glib-annotations.py index f523f926..200a02a7 100755 --- a/misc/update-glib-annotations.py +++ b/misc/update-glib-annotations.py @@ -68,7 +68,7 @@ if __name__ == '__main__': else: builddir = srcdir - print("Using source directory: %r build directory: %r" % (srcdir, builddir)) + print("Using source directory: '%s' build directory: '%s'" % (srcdir, builddir)) modules = [{'name': 'glib', 'srcname': '../gir/glib-2.0.c', @@ -105,6 +105,6 @@ if __name__ == '__main__': srcfile.close() os.rename(tmpname, srcname) - print("Updated %r" % (srcname, )) + print("Updated '%s'" % (srcname, )) print("Done; run \"git diff\" to see any changes.") diff --git a/tests/warn/warningtester.py b/tests/warn/warningtester.py index e3d677a8..81d466fa 100644 --- a/tests/warn/warningtester.py +++ b/tests/warn/warningtester.py @@ -136,16 +136,16 @@ def check(args): emitted_warnings.sort(key=sortkey) if len(expected_warnings) != len(emitted_warnings): - raise SystemExit('ERROR in %r: %d warnings were emitted, ' - 'expected %d:\n%s' % (os.path.basename(filename), + raise SystemExit("ERROR in '%s': %d warnings were emitted, " + "expected %d:\n%s" % (os.path.basename(filename), len(emitted_warnings), len(expected_warnings), _diff(expected_warnings, emitted_warnings))) for emitted_warning, expected_warning in zip(emitted_warnings, expected_warnings): if expected_warning != emitted_warning: - raise SystemExit('ERROR in %r: expected warning does not match emitted ' - 'warning:\n%s' % (filename, + raise SystemExit("ERROR in '%s': expected warning does not match emitted " + "warning:\n%s" % (filename, _diff([expected_warning], [emitted_warning]))) sys.exit(check(sys.argv[1:])) |