summaryrefslogtreecommitdiff
path: root/sphinx/util/jsdump.py
diff options
context:
space:
mode:
authorAdam Turner <9087854+AA-Turner@users.noreply.github.com>2023-01-02 00:01:14 +0000
committerGitHub <noreply@github.com>2023-01-02 00:01:14 +0000
commit4032070e8131f518bbb8a04e8d63c5af4df9b59d (patch)
tree47b14f58d5337448e8358029264ebcd6d1ae7351 /sphinx/util/jsdump.py
parentede68fa423107fbab74d07b307d7dcb03c00dfbd (diff)
downloadsphinx-git-4032070e8131f518bbb8a04e8d63c5af4df9b59d.tar.gz
Run pyupgrade (#11070)
Diffstat (limited to 'sphinx/util/jsdump.py')
-rw-r--r--sphinx/util/jsdump.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/sphinx/util/jsdump.py b/sphinx/util/jsdump.py
index 5d8a32781..e2014716b 100644
--- a/sphinx/util/jsdump.py
+++ b/sphinx/util/jsdump.py
@@ -42,13 +42,13 @@ def encode_string(s: str) -> str:
except KeyError:
n = ord(s)
if n < 0x10000:
- return '\\u%04x' % (n,)
+ return f'\\u{n:04x}'
else:
# surrogate pair
n -= 0x10000
s1 = 0xd800 | ((n >> 10) & 0x3ff)
s2 = 0xdc00 | (n & 0x3ff)
- return '\\u%04x\\u%04x' % (s1, s2)
+ return f'\\u{s1:04x}\\u{s2:04x}'
return '"' + str(ESCAPE_ASCII.sub(replace, s)) + '"'
@@ -89,10 +89,9 @@ def dumps(obj: Any, key: bool = False) -> str:
elif isinstance(obj, (int, float)):
return str(obj)
elif isinstance(obj, dict):
- return '{%s}' % ','.join(sorted('%s:%s' % (
- dumps(key, True),
- dumps(value)
- ) for key, value in obj.items()))
+ return '{%s}' % ','.join(
+ sorted(f'{dumps(key, True)}:{dumps(value)}' for key, value in obj.items())
+ )
elif isinstance(obj, set):
return '[%s]' % ','.join(sorted(dumps(x) for x in obj))
elif isinstance(obj, (tuple, list)):