mirror of
https://github.com/Instagram/LibCST.git
synced 2025-12-23 10:35:53 +00:00
Allow no spaces after as in a contextmanager in certain cases
Like in `with foo()as():pass` Raised in #930.
This commit is contained in:
parent
aa5167189c
commit
4ce3660127
2 changed files with 21 additions and 1 deletions
|
|
@ -745,7 +745,10 @@ class AsName(CSTNode):
|
|||
whitespace_after_as: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ")
|
||||
|
||||
def _validate(self) -> None:
|
||||
if self.whitespace_after_as.empty:
|
||||
if (
|
||||
self.whitespace_after_as.empty
|
||||
and not self.name._safe_to_use_with_word_operator(ExpressionPosition.RIGHT)
|
||||
):
|
||||
raise CSTValidationError(
|
||||
"There must be at least one space between 'as' and name."
|
||||
)
|
||||
|
|
|
|||
|
|
@ -102,6 +102,23 @@ class WithTest(CSTNodeTest):
|
|||
"code": "with context_mgr() as ctx: pass\n",
|
||||
"parser": parse_statement,
|
||||
},
|
||||
{
|
||||
"node": cst.With(
|
||||
(
|
||||
cst.WithItem(
|
||||
cst.Call(cst.Name("context_mgr")),
|
||||
cst.AsName(
|
||||
cst.Tuple(()),
|
||||
whitespace_after_as=cst.SimpleWhitespace(""),
|
||||
whitespace_before_as=cst.SimpleWhitespace(""),
|
||||
),
|
||||
),
|
||||
),
|
||||
cst.SimpleStatementSuite((cst.Pass(),)),
|
||||
),
|
||||
"code": "with context_mgr()as(): pass\n",
|
||||
"parser": parse_statement,
|
||||
},
|
||||
# indentation
|
||||
{
|
||||
"node": DummyIndentedBlock(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue