Skip to content

refactor: use constuctor call or comprehensions instead of loops #13159

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

Merged
merged 3 commits into from
Jul 17, 2022
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
2 changes: 1 addition & 1 deletion mypy/constraints.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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