aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/PySide2
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2020-11-02 12:50:00 +0100
committerChristian Tismer <tismer@stackless.com>2020-11-02 13:26:38 +0000
commit6e3e7b9ca0548430aaa5e2555d6e02c64625fa3f (patch)
treea821c90747c2376d1396a4bf58330f8b41ccbaad /sources/pyside2/PySide2
parent4544a943ca2df4e6f0ac24914f0c0f844dc6f748 (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/pyside2/PySide2')
-rw-r--r--sources/pyside2/PySide2/__init__.py.in5
-rw-r--r--sources/pyside2/PySide2/support/deprecated.py8
-rw-r--r--sources/pyside2/PySide2/support/generate_pyi.py31
3 files changed, 21 insertions, 23 deletions
diff --git a/sources/pyside2/PySide2/__init__.py.in b/sources/pyside2/PySide2/__init__.py.in
index 89c47ae80..f062c284a 100644
--- a/sources/pyside2/PySide2/__init__.py.in
+++ b/sources/pyside2/PySide2/__init__.py.in
@@ -68,7 +68,8 @@ def _setupQtDirectories():
# We now use an explicit function instead of touching a signature.
_init_pyside_extension()
except AttributeError:
- print(dedent('''\
+ stars = 79 * "*"
+ print(dedent(f'''\
{stars}
PySide2/__init__.py: The `signature` module was not initialized.
This libshiboken module was loaded from
@@ -77,7 +78,7 @@ def _setupQtDirectories():
Please make sure that this is the real shiboken6 binary and not just a folder.
{stars}
- ''').format(stars=79*"*", **locals()), file=sys.stderr)
+ '''), file=sys.stderr)
raise
if sys.platform == 'win32':
diff --git a/sources/pyside2/PySide2/support/deprecated.py b/sources/pyside2/PySide2/support/deprecated.py
index 57f33d9e2..af4c18e14 100644
--- a/sources/pyside2/PySide2/support/deprecated.py
+++ b/sources/pyside2/PySide2/support/deprecated.py
@@ -65,14 +65,14 @@ class PySideDeprecationWarningRemovedInQt6(Warning):
def constData(self):
cls = self.__class__
name = cls.__qualname__
- warnings.warn(dedent("""
+ warnings.warn(dedent(f"""
{name}.constData is unpythonic and will be removed in Qt For Python 6.0 .
- Please use {name}.data instead."""
- .format(**locals())), PySideDeprecationWarningRemovedInQt6, stacklevel=2)
+ Please use {name}.data instead."""), PySideDeprecationWarningRemovedInQt6, stacklevel=2)
return cls.data(self)
-def fix_for_QtGui(QtGui):
+# No longer needed but kept for reference.
+def _unused_fix_for_QtGui(QtGui):
for name, cls in QtGui.__dict__.items():
if name.startswith("QMatrix") and "data" in cls.__dict__:
cls.constData = constData
diff --git a/sources/pyside2/PySide2/support/generate_pyi.py b/sources/pyside2/PySide2/support/generate_pyi.py
index 6cca2ebbe..12ad105b9 100644
--- a/sources/pyside2/PySide2/support/generate_pyi.py
+++ b/sources/pyside2/PySide2/support/generate_pyi.py
@@ -122,8 +122,7 @@ class Formatter(Writer):
# this became _way_ too much.
# See also the comment in layout.py .
brace_pat = build_brace_pattern(3)
- pattern = (r"\b Union \s* \[ \s* {brace_pat} \s*, \s* NoneType \s* \]"
- .format(**locals()))
+ pattern = fr"\b Union \s* \[ \s* {brace_pat} \s*, \s* NoneType \s* \]"
replace = r"Optional[\1]"
optional_searcher = re.compile(pattern, flags=re.VERBOSE)
def optional_replacer(source):
@@ -165,9 +164,9 @@ class Formatter(Writer):
self.print()
here = self.outfile.tell()
if self.have_body:
- self.print("{spaces}class {class_str}:".format(**locals()))
+ self.print(f"{spaces}class {class_str}:")
else:
- self.print("{spaces}class {class_str}: ...".format(**locals()))
+ self.print(f"{spaces}class {class_str}: ...")
yield
@contextmanager
@@ -178,7 +177,7 @@ class Formatter(Writer):
spaces = indent * self.level
if type(signature) == type([]):
for sig in signature:
- self.print('{spaces}@typing.overload'.format(**locals()))
+ self.print(f'{spaces}@typing.overload')
self._function(func_name, sig, spaces)
else:
self._function(func_name, signature, spaces)
@@ -188,15 +187,15 @@ class Formatter(Writer):
def _function(self, func_name, signature, spaces):
if "self" not in tuple(signature.parameters.keys()):
- self.print('{spaces}@staticmethod'.format(**locals()))
+ self.print(f'{spaces}@staticmethod')
signature = self.optional_replacer(signature)
- self.print('{spaces}def {func_name}{signature}: ...'.format(**locals()))
+ self.print(f'{spaces}def {func_name}{signature}: ...')
@contextmanager
def enum(self, class_name, enum_name, value):
spaces = indent * self.level
hexval = hex(value)
- self.print("{spaces}{enum_name:25}: {class_name} = ... # {hexval}".format(**locals()))
+ self.print(f"{spaces}{enum_name:25}: {class_name} = ... # {hexval}")
yield
@@ -221,8 +220,7 @@ def generate_pyi(import_name, outpath, options):
top = __import__(import_name)
obj = getattr(top, plainname)
if not getattr(obj, "__file__", None) or os.path.isdir(obj.__file__):
- raise ModuleNotFoundError("We do not accept a namespace as module "
- "{plainname}".format(**locals()))
+ raise ModuleNotFoundError(f"We do not accept a namespace as module {plainname}")
module = sys.modules[import_name]
outfile = io.StringIO()
@@ -232,12 +230,12 @@ def generate_pyi(import_name, outpath, options):
if USE_PEP563:
fmt.print("from __future__ import annotations")
fmt.print()
- fmt.print(dedent('''\
+ fmt.print(dedent(f'''\
"""
This file contains the exact signatures for all functions in module
{import_name}, except for defaults which are replaced by "...".
"""
- '''.format(**locals())))
+ '''))
HintingEnumerator(fmt).module(import_name)
fmt.print()
fmt.print("# eof")
@@ -262,7 +260,7 @@ def generate_pyi(import_name, outpath, options):
wr.print()
else:
wr.print(line)
- logger.info("Generated: {outfilepath}".format(**locals()))
+ logger.info(f"Generated: {outfilepath}")
if is_py3 and (options.check or is_ci):
# Python 3: We can check the file directly if the syntax is ok.
subprocess.check_output([sys.executable, outfilepath])
@@ -292,11 +290,10 @@ def generate_all_pyi(outpath, options):
name_list = PySide2.__all__ if options.modules == ["all"] else options.modules
errors = ", ".join(set(name_list) - set(PySide2.__all__))
if errors:
- raise ImportError("The module(s) '{errors}' do not exist".format(**locals()))
+ raise ImportError(f"The module(s) '{errors}' do not exist")
quirk1, quirk2 = "QtMultimedia", "QtMultimediaWidgets"
if name_list == [quirk1]:
- logger.debug("Note: We must defer building of {quirk1}.pyi until {quirk2} "
- "is available".format(**locals()))
+ logger.debug(f"Note: We must defer building of {quirk1}.pyi until {quirk2} is available")
name_list = []
elif name_list == [quirk2]:
name_list = [quirk1, quirk2]
@@ -322,6 +319,6 @@ if __name__ == "__main__":
outpath = options.outpath
if outpath and not os.path.exists(outpath):
os.makedirs(outpath)
- logger.info("+++ Created path {outpath}".format(**locals()))
+ logger.info(f"+++ Created path {outpath}")
generate_all_pyi(outpath, options=options)
# eof