LibCST/libcst/__init__.py
Jennifer Taylor c10619ff31 Implement the walrus operator node as NamedExpr.
This implements the node, all codegen for using it and tests for construction.
This does not handle parsing, which will come in a later diff.
2019-10-24 15:25:21 -07:00

396 lines
7.5 KiB
Python

# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# pyre-strict
from libcst._batched_visitor import BatchableCSTVisitor, visit_batched
from libcst._exceptions import MetadataException, ParserSyntaxError
from libcst._helpers import ensure_type
from libcst._maybe_sentinel import MaybeSentinel
from libcst._metadata_dependent import MetadataDependent
from libcst._nodes.base import CSTNode, CSTValidationError
from libcst._nodes.expression import (
Annotation,
Arg,
Asynchronous,
Attribute,
Await,
BaseAssignTargetExpression,
BaseComp,
BaseDelTargetExpression,
BaseDict,
BaseDictElement,
BaseElement,
BaseExpression,
BaseFormattedStringContent,
BaseList,
BaseNumber,
BaseSet,
BaseSimpleComp,
BaseString,
BinaryOperation,
BooleanOperation,
Call,
Comparison,
ComparisonTarget,
CompFor,
CompIf,
ConcatenatedString,
Dict,
DictComp,
DictElement,
Element,
Ellipsis,
Float,
FormattedString,
FormattedStringExpression,
FormattedStringText,
From,
GeneratorExp,
IfExp,
Imaginary,
Index,
Integer,
Lambda,
LeftCurlyBrace,
LeftParen,
LeftSquareBracket,
List,
ListComp,
Name,
NamedExpr,
Param,
Parameters,
ParamStar,
RightCurlyBrace,
RightParen,
RightSquareBracket,
Set,
SetComp,
SimpleString,
Slice,
StarredDictElement,
StarredElement,
Subscript,
SubscriptElement,
Tuple,
UnaryOperation,
Yield,
)
from libcst._nodes.module import Module
from libcst._nodes.op import (
Add,
AddAssign,
And,
AssignEqual,
BaseAugOp,
BaseBinaryOp,
BaseBooleanOp,
BaseCompOp,
BaseUnaryOp,
BitAnd,
BitAndAssign,
BitInvert,
BitOr,
BitOrAssign,
BitXor,
BitXorAssign,
Colon,
Comma,
Divide,
DivideAssign,
Dot,
Equal,
FloorDivide,
FloorDivideAssign,
GreaterThan,
GreaterThanEqual,
ImportStar,
In,
Is,
IsNot,
LeftShift,
LeftShiftAssign,
LessThan,
LessThanEqual,
MatrixMultiply,
MatrixMultiplyAssign,
Minus,
Modulo,
ModuloAssign,
Multiply,
MultiplyAssign,
Not,
NotEqual,
NotIn,
Or,
Plus,
Power,
PowerAssign,
RightShift,
RightShiftAssign,
Semicolon,
Subtract,
SubtractAssign,
)
from libcst._nodes.statement import (
AnnAssign,
AsName,
Assert,
Assign,
AssignTarget,
AugAssign,
BaseCompoundStatement,
BaseSmallStatement,
BaseStatement,
BaseSuite,
Break,
ClassDef,
Continue,
Decorator,
Del,
Else,
ExceptHandler,
Expr,
Finally,
For,
FunctionDef,
Global,
If,
Import,
ImportAlias,
ImportFrom,
IndentedBlock,
NameItem,
Nonlocal,
Pass,
Raise,
Return,
SimpleStatementLine,
SimpleStatementSuite,
Try,
While,
With,
WithItem,
)
from libcst._nodes.whitespace import (
BaseParenthesizableWhitespace,
Comment,
EmptyLine,
Newline,
ParenthesizedWhitespace,
SimpleWhitespace,
TrailingWhitespace,
)
from libcst._parser.entrypoints import parse_expression, parse_module, parse_statement
from libcst._parser.types.config import PartialParserConfig
from libcst._position import CodePosition, CodeRange
from libcst._removal_sentinel import RemovalSentinel, RemoveFromParent
from libcst._visitors import CSTNodeT, CSTTransformer, CSTVisitor, CSTVisitorT
from libcst.metadata.base_provider import (
BaseMetadataProvider,
BatchableMetadataProvider,
VisitorMetadataProvider,
)
from libcst.metadata.wrapper import MetadataWrapper
# TODO: Remove this once we completely remove ExtSlice.
# Provide a backwards-compatible reference to deprecated ExtSlice
ExtSlice = SubscriptElement
__all__ = [
"BatchableCSTVisitor",
"CodePosition", # Deprecated export, import from libcst.metadata instead
"CodeRange", # Deprecated export, import from libcst.metadata instead
"CSTNodeT",
"CSTTransformer",
"CSTValidationError",
"CSTVisitor",
"CSTVisitorT",
"MaybeSentinel",
"MetadataException",
"ParserSyntaxError",
"PartialParserConfig",
"RemoveFromParent",
"RemovalSentinel",
"ensure_type",
"visit_batched",
"parse_module",
"parse_expression",
"parse_statement",
"CSTNode",
"Module",
"Annotation",
"Arg",
"Asynchronous",
"Attribute",
"Await",
"BaseAssignTargetExpression",
"BaseComp",
"BaseDelTargetExpression",
"BaseDict",
"BaseDictElement",
"BaseElement",
"BaseExpression",
"BaseFormattedStringContent",
"BaseList",
"BaseNumber",
"BaseSet",
"BaseSimpleComp",
"BaseString",
"BinaryOperation",
"BooleanOperation",
"Call",
"Comparison",
"ComparisonTarget",
"CompFor",
"CompIf",
"ConcatenatedString",
"Dict",
"DictComp",
"DictElement",
"Element",
"Ellipsis",
"ExtSlice",
"Float",
"FormattedString",
"FormattedStringExpression",
"FormattedStringText",
"From",
"GeneratorExp",
"IfExp",
"Imaginary",
"Index",
"Integer",
"Lambda",
"LeftCurlyBrace",
"LeftParen",
"LeftSquareBracket",
"List",
"ListComp",
"Name",
"NamedExpr",
"Param",
"Parameters",
"ParamStar",
"RightCurlyBrace",
"RightParen",
"RightSquareBracket",
"Set",
"SetComp",
"SimpleString",
"Slice",
"StarredDictElement",
"StarredElement",
"Subscript",
"SubscriptElement",
"Tuple",
"UnaryOperation",
"Yield",
"Add",
"AddAssign",
"And",
"AssignEqual",
"BaseAugOp",
"BaseBinaryOp",
"BaseBooleanOp",
"BaseCompOp",
"BaseUnaryOp",
"BitAnd",
"BitAndAssign",
"BitInvert",
"BitOr",
"BitOrAssign",
"BitXor",
"BitXorAssign",
"Colon",
"Comma",
"Divide",
"DivideAssign",
"Dot",
"Equal",
"FloorDivide",
"FloorDivideAssign",
"GreaterThan",
"GreaterThanEqual",
"ImportStar",
"In",
"Is",
"IsNot",
"LeftShift",
"LeftShiftAssign",
"LessThan",
"LessThanEqual",
"MatrixMultiply",
"MatrixMultiplyAssign",
"Minus",
"Modulo",
"ModuloAssign",
"Multiply",
"MultiplyAssign",
"Not",
"NotEqual",
"NotIn",
"Or",
"Plus",
"Power",
"PowerAssign",
"RightShift",
"RightShiftAssign",
"Semicolon",
"Subtract",
"SubtractAssign",
"AnnAssign",
"AsName",
"Assert",
"Assign",
"AssignTarget",
"AugAssign",
"BaseCompoundStatement",
"BaseSmallStatement",
"BaseStatement",
"BaseSuite",
"Break",
"ClassDef",
"Continue",
"Decorator",
"Del",
"Else",
"ExceptHandler",
"Expr",
"Finally",
"For",
"FunctionDef",
"Global",
"If",
"Import",
"ImportAlias",
"ImportFrom",
"IndentedBlock",
"NameItem",
"Nonlocal",
"Pass",
"Raise",
"Return",
"SimpleStatementLine",
"SimpleStatementSuite",
"Try",
"While",
"With",
"WithItem",
"BaseParenthesizableWhitespace",
"Comment",
"EmptyLine",
"Newline",
"ParenthesizedWhitespace",
"SimpleWhitespace",
"TrailingWhitespace",
"BaseMetadataProvider",
"BatchableMetadataProvider",
"VisitorMetadataProvider",
"MetadataDependent",
"MetadataWrapper",
]