diff --git a/mypy/constraints.py b/mypy/constraints.py index 2f071e13a002..01dce64520fb 100644 --- a/mypy/constraints.py +++ b/mypy/constraints.py @@ -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 [] diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index 9f90c7aafe69..7c6b8b95b78e 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -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: diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index ddcb78df8100..9367750c96d0 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -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]: diff --git a/mypyc/codegen/literals.py b/mypyc/codegen/literals.py index 2bbc5e6f585c..a37e6ef07221 100644 --- a/mypyc/codegen/literals.py +++ b/mypyc/codegen/literals.py @@ -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)) @@ -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 @@ -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 @@ -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 @@ -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)) @@ -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))