From fea5c9329e2442b2b77ee2408e307ccaa2c2fdfa Mon Sep 17 00:00:00 2001 From: dosisod <39638017+dosisod@users.noreply.github.com> Date: Thu, 4 May 2023 16:05:55 -0700 Subject: [PATCH] Simplify iterator usage (#15185) This PR fixes the [`FURB129`](https://github.com/dosisod/refurb/blob/master/docs/checks.md#furb129-simplify-readlines), and [`FURB130`](https://github.com/dosisod/refurb/blob/master/docs/checks.md#furb130-no-in-dict-keys) error codes in [Refurb](https://github.com/dosisod/refurb). See #14887 --- mypy/main.py | 2 +- mypy/stubtest.py | 2 +- mypyc/irbuild/expression.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index bf1c3648ff45..943030f396c5 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -1498,7 +1498,7 @@ def read_types_packages_to_install(cache_dir: str, after_run: bool) -> list[str] # No missing stubs. return [] with open(fnam) as f: - return [line.strip() for line in f.readlines()] + return [line.strip() for line in f] def install_types( diff --git a/mypy/stubtest.py b/mypy/stubtest.py index ca25c2a870e5..7b4a3b223e00 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -1667,7 +1667,7 @@ def strip_comments(s: str) -> str: return s.strip() with open(allowlist_file) as f: - for line in f.readlines(): + for line in f: entry = strip_comments(line) if entry: yield entry diff --git a/mypyc/irbuild/expression.py b/mypyc/irbuild/expression.py index 3aad620dfacf..30537777fcc1 100644 --- a/mypyc/irbuild/expression.py +++ b/mypyc/irbuild/expression.py @@ -812,10 +812,10 @@ def transform_basic_comparison( if ( is_int_rprimitive(left.type) and is_int_rprimitive(right.type) - and op in int_comparison_op_mapping.keys() + and op in int_comparison_op_mapping ): return builder.compare_tagged(left, right, op, line) - if is_fixed_width_rtype(left.type) and op in int_comparison_op_mapping.keys(): + if is_fixed_width_rtype(left.type) and op in int_comparison_op_mapping: if right.type == left.type: op_id = ComparisonOp.signed_ops[op] return builder.builder.comparison_op(left, right, op_id, line) @@ -826,7 +826,7 @@ def transform_basic_comparison( ) elif ( is_fixed_width_rtype(right.type) - and op in int_comparison_op_mapping.keys() + and op in int_comparison_op_mapping and isinstance(left, Integer) ): op_id = ComparisonOp.signed_ops[op]