Skip to content

Commit

Permalink
[minor] replace loops with comprehensions or calls (#13159)
Browse files Browse the repository at this point in the history
  • Loading branch information
anilbey committed Jul 17, 2022
1 parent 3e978b2 commit 8428af7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
2 changes: 1 addition & 1 deletion mypy/constraints.py
Expand Up @@ -269,7 +269,7 @@ def any_constraints(options: List[Optional[List[Constraint]]], eager: bool) -> L
else:
merged_option = None
merged_options.append(merged_option)
return any_constraints([option for option in merged_options], eager)
return any_constraints(list(merged_options), eager)
# Otherwise, there are either no valid options or multiple, inconsistent valid
# options. Give up and deduce nothing.
return []
Expand Down
4 changes: 1 addition & 3 deletions mypy/stubgenc.py
Expand Up @@ -74,9 +74,7 @@ def generate_stub_for_c_module(module_name: str,
if name not in done and not inspect.ismodule(obj):
type_str = strip_or_import(get_type_fullname(type(obj)), module, imports)
variables.append(f'{name}: {type_str}')
output = []
for line in sorted(set(imports)):
output.append(line)
output = sorted(set(imports))
for line in variables:
output.append(line)
for line in types:
Expand Down
5 changes: 1 addition & 4 deletions mypy/test/testcheck.py
Expand Up @@ -304,10 +304,7 @@ def find_error_message_paths(self, a: List[str]) -> Set[str]:
return hits

def find_module_files(self, manager: build.BuildManager) -> Dict[str, str]:
modules = {}
for id, module in manager.modules.items():
modules[id] = module.path
return modules
return {id: module.path for id, module in manager.modules.items()}

def find_missing_cache_files(self, modules: Dict[str, str],
manager: build.BuildManager) -> Set[str]:
Expand Down
24 changes: 6 additions & 18 deletions mypyc/codegen/literals.py
Expand Up @@ -126,9 +126,7 @@ def encoded_tuple_values(self) -> List[str]:
...
"""
values = self.tuple_literals
value_by_index = {}
for value, index in values.items():
value_by_index[index] = value
value_by_index = {index: value for value, index in values.items()}
result = []
num = len(values)
result.append(str(num))
Expand All @@ -142,9 +140,7 @@ def encoded_tuple_values(self) -> List[str]:


def _encode_str_values(values: Dict[str, int]) -> List[bytes]:
value_by_index = {}
for value, index in values.items():
value_by_index[index] = value
value_by_index = {index: value for value, index in values.items()}
result = []
line: List[bytes] = []
line_len = 0
Expand All @@ -165,9 +161,7 @@ def _encode_str_values(values: Dict[str, int]) -> List[bytes]:


def _encode_bytes_values(values: Dict[bytes, int]) -> List[bytes]:
value_by_index = {}
for value, index in values.items():
value_by_index[index] = value
value_by_index = {index: value for value, index in values.items()}
result = []
line: List[bytes] = []
line_len = 0
Expand Down Expand Up @@ -212,9 +206,7 @@ def _encode_int_values(values: Dict[int, int]) -> List[bytes]:
Values are stored in base 10 and separated by 0 bytes.
"""
value_by_index = {}
for value, index in values.items():
value_by_index[index] = value
value_by_index = {index: value for value, index in values.items()}
result = []
line: List[bytes] = []
line_len = 0
Expand Down Expand Up @@ -248,9 +240,7 @@ def _encode_float_values(values: Dict[float, int]) -> List[str]:
The result contains the number of values followed by individual values.
"""
value_by_index = {}
for value, index in values.items():
value_by_index[index] = value
value_by_index = {index: value for value, index in values.items()}
result = []
num = len(values)
result.append(str(num))
Expand All @@ -266,9 +256,7 @@ def _encode_complex_values(values: Dict[complex, int]) -> List[str]:
The result contains the number of values followed by pairs of doubles
representing complex numbers.
"""
value_by_index = {}
for value, index in values.items():
value_by_index[index] = value
value_by_index = {index: value for value, index in values.items()}
result = []
num = len(values)
result.append(str(num))
Expand Down

0 comments on commit 8428af7

Please sign in to comment.