diff options
author | Christian Tismer <tismer@stackless.com> | 2020-11-02 12:50:00 +0100 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2020-11-02 13:26:38 +0000 |
commit | 6e3e7b9ca0548430aaa5e2555d6e02c64625fa3f (patch) | |
tree | a821c90747c2376d1396a4bf58330f8b41ccbaad /sources/shiboken6/shibokenmodule | |
parent | 4544a943ca2df4e6f0ac24914f0c0f844dc6f748 (diff) |
replace **locals by f-strings where possible
This change affects mostly only my own sources which were
prepared for the migration to Python 3.6 .
Task-number: PYSIDE-904
Change-Id: I0c2cd59f6f625f51f876099c33005ac70ca39db9
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/shibokenmodule')
7 files changed, 19 insertions, 21 deletions
diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py index 8ddb75c19..df7a0bca8 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py @@ -111,21 +111,21 @@ def seterror_argument(args, func_name): # temp! found = matched_type(args, sigs) if found: - msg = dedent(""" + msg = dedent(f""" '{func_name}' called with wrong argument values: {func_name}{args} Found signature: {func_name}{found} - """.format(**locals())).strip() + """).strip() return ValueError, msg type_str = ", ".join(type(arg).__name__ for arg in args) - msg = dedent(""" + msg = dedent(f""" '{func_name}' called with wrong argument types: {func_name}({type_str}) Supported signatures: - """.format(**locals())).strip() + """).strip() for sig in sigs: - msg += "\n {func_name}{sig}".format(**locals()) + msg += f"\n {func_name}{sig}" # We don't raise the error here, to avoid the loader in the traceback. return TypeError, msg diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py index 7af43bea0..3dbc2e011 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py @@ -72,8 +72,8 @@ def finish_import(module): except Exception as e: name = e.__class__.__qualname__ print(72 * "*") - print("Error in deprecated.py, ignored:") - print(" {name}: {e}".format(**locals())) + print(f"Error in deprecated.py, ignored:") + print(f" {name}: {e}") """ A note for people who might think this could be written in pure Python: diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py index 51ce60bfa..90ea07f1b 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py @@ -102,18 +102,18 @@ class SignatureLayout(SimpleNamespace): def _attributeerror(self, err_keys): err_keys = ", ".join(err_keys) allowed_keys = ", ".join(self.allowed_keys.__dict__.keys()) - raise AttributeError(dedent("""\ + raise AttributeError(dedent(f"""\ Not allowed: '{err_keys}'. The only allowed keywords are '{allowed_keys}'. - """.format(**locals()))) + """)) def _valueerror(self, err_values): err_values = ", ".join(map(str, err_values)) allowed_values = ", ".join(map(str, self.allowed_values)) - raise ValueError(dedent("""\ + raise ValueError(dedent(f"""\ Not allowed: '{err_values}'. The only allowed values are '{allowed_values}'. - """.format(**locals()))) + """)) # The following names are used literally in this module. # This way, we avoid the dict hashing problem. 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 371b3ca4a..dcbdd657c 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 @@ -147,8 +147,7 @@ class ExactEnumerator(object): if klass == subclass: # this is a side effect of the typing module for Python 2.7 # via the "._gorg" property, which we can safely ignore. - print("Warning: {class_name} points to itself via {subclass_name}, skipped!" - .format(**locals())) + print(f"Warning: {class_name} points to itself via {subclass_name}, skipped!") continue ret.update(self.klass(subclass_name, subclass)) self.fmt.class_name = class_name 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 24e75e42c..6d72fa5db 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py @@ -106,8 +106,8 @@ def build_brace_pattern(level, separators=""): ro, rc, so, sc, co, cc, ao, ac, separators, qu, bs, all = map( escape, (ro, rc, so, sc, co, cc, ao, ac, separators, qu, bs, all)) - no_brace_sep_q = r"[^{all}{separators}{qu}{bs}]".format(**locals()) - no_quote = r"(?: [^{qu}{bs}] | {bs}. )*".format(**locals()) + no_brace_sep_q = fr"[^{all}{separators}{qu}{bs}]" + no_quote = fr"(?: [^{qu}{bs}] | {bs}. )*" pattern = dedent(r""" ( (?: {__} {no_brace_sep_q} @@ -119,7 +119,7 @@ def build_brace_pattern(level, separators=""): )+ ) """) - no_braces_q = "[^{all}{qu}{bs}]*".format(**locals()) + no_braces_q = f"[^{all}{qu}{bs}]*" repeated = dedent(r""" {indent} (?: {__} {no_braces_q} {indent} | {qu} {no_quote} {qu} diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py index c043b8435..43be5b95f 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py @@ -217,8 +217,7 @@ def check_module(mod): # without enforcing an '__init__.py'. if not Reloader.module_valid(mod): mod_name = mod.__name__ - raise ImportError("Module '{mod_name}' is not a binary module!" - .format(**locals())) + raise ImportError(f"Module '{mod_name}' is not a binary module!") update_mapping = Reloader().update type_map = {} diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py index 20c791cc1..6bf78cf95 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -235,7 +235,7 @@ matrix_pattern = "PySide2.QtGui.QGenericMatrix" def handle_matrix(arg): n, m, typstr = tuple(map(lambda x:x.strip(), arg.split(","))) assert typstr == "float" - result = "PySide2.QtGui.QMatrix{n}x{m}".format(**locals()) + result = f"PySide2.QtGui.QMatrix{n}x{m}" return eval(result, namespace) @@ -245,7 +245,7 @@ from inspect import currentframe def lno(level): lineno = currentframe().f_back.f_lineno spaces = level * " " - return "{lineno}{spaces}".format(**locals()) + return f"{lineno}{spaces}" """ @@ -276,7 +276,7 @@ def _resolve_type(thing, line, level, var_handler): part = repr(part) pieces.append(to_string(part)) thing = ", ".join(pieces) - result = "{contr}[{thing}]".format(**locals()) + result = f"{contr}[{thing}]" return eval(result, namespace) return _resolve_value(thing, None, line) |