Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Minor refactoring of dict literal usage #16837

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions mypy/dmypy_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def __init__(self, server: IPCBase, output_key: str = "stdout") -> None:
self.output_key = output_key

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 @@ -1454,9 +1454,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()
return data
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
Loading