diff options
author | Cristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2021-01-04 21:03:22 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-01-06 15:34:36 +0000 |
commit | 5ea0fde59719866f6eb86a4fe4e33d7f389802c5 (patch) | |
tree | db7305af8d7642b4fddf032ece79dc65d2c95ad4 /sources/shiboken6 | |
parent | b9a89e1f3c8d0b80cc91bf1d277ead3b7857dabd (diff) |
sources: migration from format() to f-strings
This should be the last patch related the usage of f-strings
from the 'sources' directory.
Change-Id: I0288d720dc4930dee088ca3396a66d1b3ba18f76
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit d9f344fcef6bec04a787f9ea9f4ea94f15eaa26c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'sources/shiboken6')
10 files changed, 32 insertions, 30 deletions
diff --git a/sources/shiboken6/libshiboken/embed/embedding_generator.py b/sources/shiboken6/libshiboken/embed/embedding_generator.py index 2c03cf686..a88da8d66 100644 --- a/sources/shiboken6/libshiboken/embed/embedding_generator.py +++ b/sources/shiboken6/libshiboken/embed/embedding_generator.py @@ -214,7 +214,8 @@ def _embed_bytefile(fin, fout, is_text): use_ord = sys.version_info[0] == 2 for i in range(0, len(binstr), 16): for c in bytes(binstr[i : i + 16]): - print("{:#4},".format(ord(c) if use_ord else c), file=fout, end="") + ord_c = ord(c) if use_ord else c + print(f"{ord_c:#4},", file=fout, end="") print(file=fout) print("/* End Of File */", file=fout) diff --git a/sources/shiboken6/shiboken_version.py b/sources/shiboken6/shiboken_version.py index 88b65353f..b5ebfa59c 100644 --- a/sources/shiboken6/shiboken_version.py +++ b/sources/shiboken6/shiboken_version.py @@ -51,5 +51,5 @@ pre_release_version = "1" if __name__ == '__main__': # Used by CMake. - print('{0};{1};{2};{3};{4}'.format(major_version, minor_version, patch_version, - release_version_type, pre_release_version)) + print(f'{major_version};{minor_version};{patch_version};' + f'{release_version_type};{pre_release_version}') diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/__feature__.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/__feature__.py index 48a47d511..0fa58d22f 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/__feature__.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/__feature__.py @@ -117,7 +117,7 @@ def _import(name, *args, **kwargs): if feature in _really_all_feature_names: flag |= globals()[feature] else: - raise SyntaxError("PySide feature {} is not defined".format(feature)) + raise SyntaxError(f"PySide feature {feature} is not defined") flag |= existing & 255 if isinstance(existing, int) and existing >= 0 else 0 pyside_feature_dict[importing_module] = flag diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/fix-complaints.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/fix-complaints.py index 284664aef..cc819e070 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/fix-complaints.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/fix-complaints.py @@ -60,8 +60,7 @@ offending_words = { } utf8_line = "# This Python file uses the following encoding: utf-8\n" -marker_line = "# It has been edited by {} .\n".format( - os.path.basename(__file__)) +marker_line = f"# It has been edited by {os.path.basename(__file__)} .\n" def patch_file(fname): with open(fname) as f: @@ -71,7 +70,7 @@ def patch_file(fname): for word, repl in offending_words.items(): if word in line: lines[idx] = line.replace(word, repl) - print("line:{!r} {!r}->{!r}".format(line, word, repl)) + print(f"line:{line!r} {word!r}->{repl!r}") if lines[0].strip() != utf8_line.strip(): lines[:0] = [utf8_line, "\n"] if lines[1] != marker_line: diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py index 6d832627e..99052e50e 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py @@ -110,7 +110,8 @@ class ExactEnumerator(object): if name not in ("object", "type"): name = base.__module__ + "." + name bases_list.append(name) - class_str = "{}({})".format(class_name, ", ".join(bases_list)) + bases_str = ', '.join(bases_list) + class_str = f"{class_name}({bases_str})" # class_members = inspect.getmembers(klass) # gives us also the inherited things. class_members = sorted(list(klass.__dict__.items())) diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py index 83da63891..268142db8 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py @@ -55,8 +55,9 @@ class SimpleNamespace(object): def __repr__(self): keys = sorted(self.__dict__) - items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys) - return "{}({})".format(type(self).__name__, ", ".join(items)) + items = (f"{k}={self.__dict__[k]!r}" for k in keys) + items_str = ', '.join(items) + return f"{type(self).__name__}({items_str})" def __eq__(self, other): return self.__dict__ == other.__dict__ diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/loader.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/loader.py index 5a056aafd..e685da166 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/loader.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/loader.py @@ -135,7 +135,7 @@ def put_into_package(package, module, override=None): if package: setattr(package, name, module) # put into sys.modules as a package to allow all import options - fullname = "{}.{}".format(_get_modname(package), name) if package else name + fullname = f"{_get_modname(package)}.{name}" if package else name _set_modname(module, fullname) # publish new dotted name in sys.modules sys.modules[fullname] = module @@ -147,7 +147,7 @@ def list_modules(message): if hasattr(value, "__file__")} print("SYS.MODULES", message, len(sys.modules), len(ext_modules)) for (name, module) in sorted(ext_modules.items()): - print(" {:23}".format(name), repr(module)[:70]) + print(f" {name:23}", repr(module)[:70]) orig_typing = True diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py index 70bcc4822..97991d4f9 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py @@ -103,7 +103,7 @@ class _NotCalled(str): real object is needed, the wrapper can simply be called. """ def __repr__(self): - return "{}({})".format(type(self).__name__, self) + return f"{type(self).__name__}({self})" def __call__(self): from shibokensupport.signature.mapping import __dict__ as namespace @@ -128,7 +128,7 @@ class Missing(_NotCalled): def __repr__(self): if USE_PEP563: return _NotCalled.__repr__(self) - return '{}("{}")'.format(type(self).__name__, self) + return f'{type(self).__name__}("{self}")' class Invalid(_NotCalled): @@ -149,8 +149,7 @@ class _Parameterized(object): self.__name__ = self.__class__.__name__ def __repr__(self): - return "{}({})".format( - type(self).__name__, self.type.__name__) + return f"{type(self).__name__}({self.type.__name__})" # Mark the primitive variables to be moved into the result. class ResultVariable(_Parameterized): diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py index 49c0ca5be..d737c2a54 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -141,11 +141,11 @@ def _parse_line(line): def make_good_value(thing, valtype): try: if thing.endswith("()"): - thing = 'Default("{}")'.format(thing[:-2]) + thing = f'Default("{thing[:-2]}")' else: ret = eval(thing, namespace) if valtype and repr(ret).startswith("<"): - thing = 'Instance("{}")'.format(thing) + thing = f'Instance("{thing}")' return eval(thing, namespace) except Exception: pass @@ -153,7 +153,7 @@ def make_good_value(thing, valtype): def try_to_guess(thing, valtype): if "." not in thing and "(" not in thing: - text = "{}.{}".format(valtype, thing) + text = f"{valtype}.{thing}" ret = make_good_value(text, valtype) if ret is not None: return ret @@ -183,7 +183,7 @@ def _resolve_value(thing, valtype, line): map = type_map[valtype] # typing.Any: '_SpecialForm' object has no attribute '__name__' name = get_name(map) if hasattr(map, "__name__") else str(map) - thing = "zero({})".format(name) + thing = f"zero({name})" if thing in type_map: return type_map[thing] res = make_good_value(thing, valtype) @@ -194,11 +194,11 @@ def _resolve_value(thing, valtype, line): if res is not None: type_map[thing] = res return res - warnings.warn("""pyside_type_init: + warnings.warn(f"""pyside_type_init: - UNRECOGNIZED: {!r} - OFFENDING LINE: {!r} - """.format(thing, line), RuntimeWarning) + UNRECOGNIZED: {thing!r} + OFFENDING LINE: {line!r} + """, RuntimeWarning) return thing @@ -397,7 +397,8 @@ def fix_variables(props, line): if len(retvars) == 1: returntype = retvars[0] else: - typestr = "typing.Tuple[{}]".format(", ".join(map(to_string, retvars))) + retvars_str = ", ".join(map(to_string, retvars)) + typestr = f"typing.Tuple[{retvars_str}]" returntype = eval(typestr, namespace) props.annotations["return"] = returntype props.varnames = tuple(varnames) @@ -425,7 +426,7 @@ def fixup_multilines(lines): nmulti = len(multi_lines) if nmulti > 1: for idx, line in enumerate(multi_lines): - res.append("{}:{}".format(nmulti-idx-1, line)) + res.append(f"{nmulti-idx-1}:{line}") else: res.append(multi_lines[0]) multi_lines = [] @@ -436,7 +437,7 @@ def fixup_multilines(lines): def pyside_type_init(type_key, sig_strings): dprint() - dprint("Initialization of type key '{}'".format(type_key)) + dprint(f"Initialization of type key '{type_key}'") update_mapping() lines = fixup_multilines(sig_strings) ret = {} diff --git a/sources/shiboken6/tests/shiboken_paths.py b/sources/shiboken6/tests/shiboken_paths.py index 382079c36..29535f1b0 100644 --- a/sources/shiboken6/tests/shiboken_paths.py +++ b/sources/shiboken6/tests/shiboken_paths.py @@ -35,9 +35,9 @@ def get_dir_env_var(var_name): """Return a directory set by an environment variable""" result = os.environ.get(var_name) if not result: - raise ValueError('{} is not set!'.format(var_name)) + raise ValueError(f'{var_name} is not set!') if not os.path.isdir(result): - raise ValueError('{} is not a directory!'.format(result)) + raise ValueError(f'{result} is not a directory!') return result @@ -71,7 +71,7 @@ def _prepend_path_var(var_name, paths): old_paths = os.environ.get(var_name) new_paths = os.pathsep.join(paths) if old_paths: - new_paths += '{}{}'.format(os.pathsep, old_paths) + new_paths += f'{os.pathsep}{old_paths}' os.environ[var_name] = new_paths |