mirror of
https://github.com/Instagram/LibCST.git
synced 2025-12-23 10:35:53 +00:00
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!
This commit is contained in:
parent
a6ab27ecee
commit
dbe4a1be5b
6 changed files with 13 additions and 23 deletions
|
|
@ -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,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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(),),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
),
|
||||
(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue