From dbe4a1be5bb6917f69bc9356159ee4d6b696ba0f Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Wed, 17 Jul 2019 15:47:42 -0700 Subject: [PATCH] Fix some pyre errors in test Some of these crept in before we had type-checking on node constructors or decorators. So, lets fix these cases and get rid of a few incorrect constructions in tests! --- libcst/nodes/tests/test_assert.py | 2 +- libcst/nodes/tests/test_atom.py | 8 ++------ libcst/nodes/tests/test_binary_op.py | 8 ++------ libcst/nodes/tests/test_call.py | 6 ++---- libcst/nodes/tests/test_cst_node.py | 6 +++--- libcst/nodes/tests/test_import.py | 6 +++--- 6 files changed, 13 insertions(+), 23 deletions(-) diff --git a/libcst/nodes/tests/test_assert.py b/libcst/nodes/tests/test_assert.py index 0749381c..aba845e1 100644 --- a/libcst/nodes/tests/test_assert.py +++ b/libcst/nodes/tests/test_assert.py @@ -94,7 +94,7 @@ class AssertParsingTest(CSTNodeTest): { "node": cst.Assert(cst.Name("True")), "code": "assert True", - # pyre-ignore[16] + # pyre-fixme[16]: `BaseSuite` has no attribute `__getitem__`. "parser": (lambda code: parse_statement(code).body[0]), "expected_position": None, }, diff --git a/libcst/nodes/tests/test_atom.py b/libcst/nodes/tests/test_atom.py index f97ea117..d0568ada 100644 --- a/libcst/nodes/tests/test_atom.py +++ b/libcst/nodes/tests/test_atom.py @@ -694,17 +694,13 @@ class AtomTest(CSTNodeTest): }, { "get_node": ( - # pyre-fixme[6]: Expected `Sequence[BaseFormattedStringContent]` for - # 1st param but got `str`. - lambda: cst.FormattedString("f''", lpar=(cst.LeftParen(),)) + lambda: cst.FormattedString(parts=(), lpar=(cst.LeftParen(),)) ), "expected_re": "left paren without right paren", }, { "get_node": ( - # pyre-fixme[6]: Expected `Sequence[BaseFormattedStringContent]` for - # 1st param but got `str`. - lambda: cst.FormattedString("f''", rpar=(cst.RightParen(),)) + lambda: cst.FormattedString(parts=(), rpar=(cst.RightParen(),)) ), "expected_re": "right paren without left paren", }, diff --git a/libcst/nodes/tests/test_binary_op.py b/libcst/nodes/tests/test_binary_op.py index 60d951a1..79081da6 100644 --- a/libcst/nodes/tests/test_binary_op.py +++ b/libcst/nodes/tests/test_binary_op.py @@ -154,9 +154,7 @@ class BinaryOperationTest(CSTNodeTest): "get_node": ( lambda: cst.BinaryOperation( cst.Name("foo"), - # pyre-fixme[6]: Expected `BaseBinaryOp` for 2nd param but got - # `Plus`. - cst.Plus(), + cst.Add(), cst.Name("bar"), lpar=(cst.LeftParen(),), ) @@ -167,9 +165,7 @@ class BinaryOperationTest(CSTNodeTest): "get_node": ( lambda: cst.BinaryOperation( cst.Name("foo"), - # pyre-fixme[6]: Expected `BaseBinaryOp` for 2nd param but got - # `Plus`. - cst.Plus(), + cst.Add(), cst.Name("bar"), rpar=(cst.RightParen(),), ) diff --git a/libcst/nodes/tests/test_call.py b/libcst/nodes/tests/test_call.py index f7597c1a..6fc35033 100644 --- a/libcst/nodes/tests/test_call.py +++ b/libcst/nodes/tests/test_call.py @@ -466,10 +466,8 @@ class CallTest(CSTNodeTest): ( lambda: cst.Call( func=cst.Name("foo"), - # pyre-fixme[6]: Expected `Union[typing_extensions.Literal[''], - # typing_extensions.Literal['*'], - # typing_extensions.Literal['**']]` for 1st param but got - # `typing_extensions.Literal['***']`. + # pyre-ignore: Ignore type on 'star' since we're testing behavior + # when somebody isn't using a type checker. args=(cst.Arg(star="***", value=cst.SimpleString("'baz'")),), ), r"Must specify either '', '\*' or '\*\*' for star", diff --git a/libcst/nodes/tests/test_cst_node.py b/libcst/nodes/tests/test_cst_node.py index d76ac5a2..92d93dce 100644 --- a/libcst/nodes/tests/test_cst_node.py +++ b/libcst/nodes/tests/test_cst_node.py @@ -41,6 +41,8 @@ class _TestVisitor(CSTTransformer): self, original_node: _CSTNodeT, updated_node: _CSTNodeT ) -> Union[_CSTNodeT, RemovalSentinel]: self.test.assertTrue(original_node.deep_equals(updated_node)) + # Don't allow type checkers to accidentally refine our return type. + return_node = updated_node if isinstance(updated_node, cst.Pass): self.assert_counter(3) elif isinstance(updated_node, cst.Newline): @@ -49,9 +51,7 @@ class _TestVisitor(CSTTransformer): self.assert_counter(6) elif isinstance(updated_node, cst.Module): self.assert_counter(7) - # pyre: Expected `Union[RemovalSentinel, Variable[_CSTNodeT (bound to - # pyre-ignore[7]: cst._base.CSTNode)]]` but got `cst._statement.Pass`. - return updated_node + return return_node class CSTNodeTest(UnitTest): diff --git a/libcst/nodes/tests/test_import.py b/libcst/nodes/tests/test_import.py index a75b4a82..4ae89272 100644 --- a/libcst/nodes/tests/test_import.py +++ b/libcst/nodes/tests/test_import.py @@ -483,9 +483,9 @@ class ImportFromCreateTest(CSTNodeTest): @data_provider( ( ( - # pyre-fixme[6]: Expected `Union[Sequence[ImportAlias], ImportStar]` - # for 2nd param but got `Tuple[Name]`. - lambda: cst.ImportFrom(module=None, names=(cst.Name("bar"),)), + lambda: cst.ImportFrom( + module=None, names=(cst.ImportAlias(cst.Name("bar")),) + ), "Must have a module specified", ), (