Skip to content

Commit e1d09d3

Browse files
authored
Minor refactoring of dict literal usage (python#16837)
1 parent 946c1bf commit e1d09d3

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

mypy/dmypy_util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def truncate(self, size: int | None = 0) -> int:
104104
raise io.UnsupportedOperation
105105

106106
def write(self, output: str) -> int:
107-
resp: dict[str, Any] = {}
108-
resp[self.output_key] = output
107+
resp: dict[str, Any] = {self.output_key: output}
109108
send(self.server, resp)
110109
return len(output)
111110

mypy/gclogger.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ def __exit__(self, *args: object) -> None:
3838

3939
def get_stats(self) -> Mapping[str, float]:
4040
end_time = time.time()
41-
result = {}
42-
result["gc_time"] = self.gc_time
43-
result["gc_calls"] = self.gc_calls
44-
result["gc_collected"] = self.gc_collected
45-
result["gc_uncollectable"] = self.gc_uncollectable
46-
result["build_time"] = end_time - self.start_time
41+
result = {
42+
"gc_time": self.gc_time,
43+
"gc_calls": self.gc_calls,
44+
"gc_collected": self.gc_collected,
45+
"gc_uncollectable": self.gc_uncollectable,
46+
"build_time": end_time - self.start_time,
47+
}
4748
return result

mypy/server/update.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,8 +1059,7 @@ def find_symbol_tables_recursive(prefix: str, symbols: SymbolTable) -> dict[str,
10591059
10601060
Returns a dictionary from full name to corresponding symbol table.
10611061
"""
1062-
result = {}
1063-
result[prefix] = symbols
1062+
result = {prefix: symbols}
10641063
for name, node in symbols.items():
10651064
if isinstance(node.node, TypeInfo) and node.node.fullname.startswith(prefix + "."):
10661065
more = find_symbol_tables_recursive(prefix + "." + name, node.node.names)

mypy/types.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,9 +1493,11 @@ def serialize(self) -> JsonDict | str:
14931493
type_ref = self.type.fullname
14941494
if not self.args and not self.last_known_value:
14951495
return type_ref
1496-
data: JsonDict = {".class": "Instance"}
1497-
data["type_ref"] = type_ref
1498-
data["args"] = [arg.serialize() for arg in self.args]
1496+
data: JsonDict = {
1497+
".class": "Instance",
1498+
"type_ref": type_ref,
1499+
"args": [arg.serialize() for arg in self.args],
1500+
}
14991501
if self.last_known_value is not None:
15001502
data["last_known_value"] = self.last_known_value.serialize()
15011503
data["extra_attrs"] = self.extra_attrs.serialize() if self.extra_attrs else None

mypyc/codegen/emitclass.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ def generate_class(cl: ClassIR, module: str, emitter: Emitter) -> None:
213213
methods_name = f"{name_prefix}_methods"
214214
vtable_setup_name = f"{name_prefix}_trait_vtable_setup"
215215

216-
fields: dict[str, str] = {}
217-
fields["tp_name"] = f'"{name}"'
216+
fields: dict[str, str] = {"tp_name": f'"{name}"'}
218217

219218
generate_full = not cl.is_trait and not cl.builtin_base
220219
needs_getseters = cl.needs_getseters or not cl.is_generated or cl.has_dict

0 commit comments

Comments
 (0)