Skip to content

Commit

Permalink
Minor refactoring of dict literal usage (python#16837)
Browse files Browse the repository at this point in the history
  • Loading branch information
nautics889 authored Oct 17, 2024
1 parent 946c1bf commit e1d09d3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
3 changes: 1 addition & 2 deletions mypy/dmypy_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def truncate(self, size: int | None = 0) -> int:
raise io.UnsupportedOperation

def write(self, output: str) -> int:
resp: dict[str, Any] = {}
resp[self.output_key] = output
resp: dict[str, Any] = {self.output_key: output}
send(self.server, resp)
return len(output)

Expand Down
13 changes: 7 additions & 6 deletions mypy/gclogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ def __exit__(self, *args: object) -> None:

def get_stats(self) -> Mapping[str, float]:
end_time = time.time()
result = {}
result["gc_time"] = self.gc_time
result["gc_calls"] = self.gc_calls
result["gc_collected"] = self.gc_collected
result["gc_uncollectable"] = self.gc_uncollectable
result["build_time"] = end_time - self.start_time
result = {
"gc_time": self.gc_time,
"gc_calls": self.gc_calls,
"gc_collected": self.gc_collected,
"gc_uncollectable": self.gc_uncollectable,
"build_time": end_time - self.start_time,
}
return result
3 changes: 1 addition & 2 deletions mypy/server/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,7 @@ def find_symbol_tables_recursive(prefix: str, symbols: SymbolTable) -> dict[str,
Returns a dictionary from full name to corresponding symbol table.
"""
result = {}
result[prefix] = symbols
result = {prefix: symbols}
for name, node in symbols.items():
if isinstance(node.node, TypeInfo) and node.node.fullname.startswith(prefix + "."):
more = find_symbol_tables_recursive(prefix + "." + name, node.node.names)
Expand Down
8 changes: 5 additions & 3 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1493,9 +1493,11 @@ def serialize(self) -> JsonDict | str:
type_ref = self.type.fullname
if not self.args and not self.last_known_value:
return type_ref
data: JsonDict = {".class": "Instance"}
data["type_ref"] = type_ref
data["args"] = [arg.serialize() for arg in self.args]
data: JsonDict = {
".class": "Instance",
"type_ref": type_ref,
"args": [arg.serialize() for arg in self.args],
}
if self.last_known_value is not None:
data["last_known_value"] = self.last_known_value.serialize()
data["extra_attrs"] = self.extra_attrs.serialize() if self.extra_attrs else None
Expand Down
3 changes: 1 addition & 2 deletions mypyc/codegen/emitclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ def generate_class(cl: ClassIR, module: str, emitter: Emitter) -> None:
methods_name = f"{name_prefix}_methods"
vtable_setup_name = f"{name_prefix}_trait_vtable_setup"

fields: dict[str, str] = {}
fields["tp_name"] = f'"{name}"'
fields: dict[str, str] = {"tp_name": f'"{name}"'}

generate_full = not cl.is_trait and not cl.builtin_base
needs_getseters = cl.needs_getseters or not cl.is_generated or cl.has_dict
Expand Down

0 comments on commit e1d09d3

Please sign in to comment.