diff --git a/libcst/__init__.py b/libcst/__init__.py index e0bacdc1..3ea349cf 100644 --- a/libcst/__init__.py +++ b/libcst/__init__.py @@ -177,9 +177,9 @@ from libcst._nodes._whitespace import ( SimpleWhitespace, TrailingWhitespace, ) +from libcst._parser._entrypoints import parse_expression, parse_module, parse_statement from libcst._removal_sentinel import RemovalSentinel from libcst._visitors import CSTNodeT, CSTTransformer, CSTVisitor, CSTVisitorT -from libcst.parser._entrypoints import parse_expression, parse_module, parse_statement __all__ = [ diff --git a/libcst/parser/__init__.py b/libcst/_parser/__init__.py similarity index 100% rename from libcst/parser/__init__.py rename to libcst/_parser/__init__.py diff --git a/libcst/parser/_base_parser.py b/libcst/_parser/_base_parser.py similarity index 99% rename from libcst/parser/_base_parser.py rename to libcst/_parser/_base_parser.py index 56949d68..b143a155 100644 --- a/libcst/parser/_base_parser.py +++ b/libcst/_parser/_base_parser.py @@ -31,7 +31,7 @@ from parso.pgen2.generator import DFAState, Grammar, ReservedString from parso.python.token import TokenType from libcst._exceptions import ParserSyntaxError -from libcst.parser._types.token import Token +from libcst._parser._types.token import Token _NodeT = TypeVar("_NodeT") diff --git a/libcst/parser/_conversions/README.md b/libcst/_parser/_conversions/README.md similarity index 100% rename from libcst/parser/_conversions/README.md rename to libcst/_parser/_conversions/README.md diff --git a/libcst/parser/_conversions/__init__.py b/libcst/_parser/_conversions/__init__.py similarity index 100% rename from libcst/parser/_conversions/__init__.py rename to libcst/_parser/_conversions/__init__.py diff --git a/libcst/parser/_conversions/dummy.py b/libcst/_parser/_conversions/dummy.py similarity index 87% rename from libcst/parser/_conversions/dummy.py rename to libcst/_parser/_conversions/dummy.py index 9848fd59..f2180a31 100644 --- a/libcst/parser/_conversions/dummy.py +++ b/libcst/_parser/_conversions/dummy.py @@ -7,10 +7,10 @@ from typing import Any, List, Sequence, Union from libcst._nodes._base import CSTNode from libcst._nodes._dummy import DummyNode -from libcst.parser._types.config import ParserConfig -from libcst.parser._types.partials import WithLeadingWhitespace -from libcst.parser._types.token import Token -from libcst.parser._whitespace_parser import parse_parenthesizable_whitespace +from libcst._parser._types.config import ParserConfig +from libcst._parser._types.partials import WithLeadingWhitespace +from libcst._parser._types.token import Token +from libcst._parser._whitespace_parser import parse_parenthesizable_whitespace def make_dummy_node(config: ParserConfig, children: Sequence[Any]) -> Any: diff --git a/libcst/parser/_conversions/expression.py b/libcst/_parser/_conversions/expression.py similarity index 99% rename from libcst/parser/_conversions/expression.py rename to libcst/_parser/_conversions/expression.py index 43f41f54..55def8ae 100644 --- a/libcst/parser/_conversions/expression.py +++ b/libcst/_parser/_conversions/expression.py @@ -99,11 +99,11 @@ from libcst._nodes._op import ( Subtract, ) from libcst._nodes._whitespace import SimpleWhitespace -from libcst.parser._conversions.dummy import make_dummy_node -from libcst.parser._custom_itertools import grouper -from libcst.parser._production_decorator import with_production -from libcst.parser._types.config import ParserConfig -from libcst.parser._types.partials import ( +from libcst._parser._conversions.dummy import make_dummy_node +from libcst._parser._custom_itertools import grouper +from libcst._parser._production_decorator import with_production +from libcst._parser._types.config import ParserConfig +from libcst._parser._types.partials import ( ArglistPartial, AttributePartial, CallPartial, @@ -113,8 +113,8 @@ from libcst.parser._types.partials import ( SubscriptPartial, WithLeadingWhitespace, ) -from libcst.parser._types.token import Token -from libcst.parser._whitespace_parser import parse_parenthesizable_whitespace +from libcst._parser._types.token import Token +from libcst._parser._whitespace_parser import parse_parenthesizable_whitespace BINOP_TOKEN_LUT: typing.Dict[str, typing.Type[BaseBinaryOp]] = { diff --git a/libcst/parser/_conversions/module.py b/libcst/_parser/_conversions/module.py similarity index 93% rename from libcst/parser/_conversions/module.py rename to libcst/_parser/_conversions/module.py index 1514b25d..508a28a6 100644 --- a/libcst/parser/_conversions/module.py +++ b/libcst/_parser/_conversions/module.py @@ -7,8 +7,8 @@ from typing import Any, Sequence from libcst._nodes._module import Module from libcst._nodes._whitespace import NEWLINE_RE -from libcst.parser._production_decorator import with_production -from libcst.parser._types.config import ParserConfig +from libcst._parser._production_decorator import with_production +from libcst._parser._types.config import ParserConfig @with_production("file_input", "(NEWLINE | stmt)* ENDMARKER") diff --git a/libcst/parser/_conversions/params.py b/libcst/_parser/_conversions/params.py similarity index 96% rename from libcst/parser/_conversions/params.py rename to libcst/_parser/_conversions/params.py index a1c734b5..c5b9f49b 100644 --- a/libcst/parser/_conversions/params.py +++ b/libcst/_parser/_conversions/params.py @@ -8,11 +8,11 @@ from typing import Any, List, Optional, Sequence, Union from libcst._maybe_sentinel import MaybeSentinel from libcst._nodes._expression import Annotation, Name, Param, Parameters, ParamStar from libcst._nodes._op import AssignEqual, Comma -from libcst.parser._custom_itertools import grouper -from libcst.parser._production_decorator import with_production -from libcst.parser._types.config import ParserConfig -from libcst.parser._types.partials import ParamStarPartial -from libcst.parser._whitespace_parser import parse_parenthesizable_whitespace +from libcst._parser._custom_itertools import grouper +from libcst._parser._production_decorator import with_production +from libcst._parser._types.config import ParserConfig +from libcst._parser._types.partials import ParamStarPartial +from libcst._parser._whitespace_parser import parse_parenthesizable_whitespace @with_production( # noqa: C901: too complex diff --git a/libcst/parser/_conversions/statement.py b/libcst/_parser/_conversions/statement.py similarity index 99% rename from libcst/parser/_conversions/statement.py rename to libcst/_parser/_conversions/statement.py index d3a972b0..6bf3325d 100644 --- a/libcst/parser/_conversions/statement.py +++ b/libcst/_parser/_conversions/statement.py @@ -77,10 +77,10 @@ from libcst._nodes._statement import ( WithItem, ) from libcst._nodes._whitespace import EmptyLine, SimpleWhitespace -from libcst.parser._custom_itertools import grouper -from libcst.parser._production_decorator import with_production -from libcst.parser._types.config import ParserConfig -from libcst.parser._types.partials import ( +from libcst._parser._custom_itertools import grouper +from libcst._parser._production_decorator import with_production +from libcst._parser._types.config import ParserConfig +from libcst._parser._types.partials import ( AnnAssignPartial, AssignPartial, AugAssignPartial, @@ -92,8 +92,8 @@ from libcst.parser._types.partials import ( SimpleStatementPartial, WithLeadingWhitespace, ) -from libcst.parser._types.token import Token -from libcst.parser._whitespace_parser import ( +from libcst._parser._types.token import Token +from libcst._parser._whitespace_parser import ( parse_empty_lines, parse_parenthesizable_whitespace, parse_simple_whitespace, diff --git a/libcst/parser/_conversions/terminals.py b/libcst/_parser/_conversions/terminals.py similarity index 91% rename from libcst/parser/_conversions/terminals.py rename to libcst/_parser/_conversions/terminals.py index a8f1927b..a4841a3d 100644 --- a/libcst/parser/_conversions/terminals.py +++ b/libcst/_parser/_conversions/terminals.py @@ -6,10 +6,10 @@ from typing import Any from libcst._nodes._expression import SimpleString -from libcst.parser._types.config import ParserConfig -from libcst.parser._types.partials import WithLeadingWhitespace -from libcst.parser._types.token import Token -from libcst.parser._whitespace_parser import ( +from libcst._parser._types.config import ParserConfig +from libcst._parser._types.partials import WithLeadingWhitespace +from libcst._parser._types.token import Token +from libcst._parser._whitespace_parser import ( parse_empty_lines, parse_trailing_whitespace, ) diff --git a/libcst/parser/_custom_itertools.py b/libcst/_parser/_custom_itertools.py similarity index 100% rename from libcst/parser/_custom_itertools.py rename to libcst/_parser/_custom_itertools.py diff --git a/libcst/parser/_detect_config.py b/libcst/_parser/_detect_config.py similarity index 95% rename from libcst/parser/_detect_config.py rename to libcst/_parser/_detect_config.py index 9341fb8f..cf7d4990 100644 --- a/libcst/parser/_detect_config.py +++ b/libcst/_parser/_detect_config.py @@ -15,9 +15,9 @@ from parso.python.token import PythonTokenTypes, TokenType from parso.utils import split_lines from libcst._nodes._whitespace import NEWLINE_RE -from libcst.parser._types.config import AutoConfig, ParserConfig, PartialParserConfig -from libcst.parser._types.token import Token -from libcst.parser._wrapped_tokenize import tokenize_lines +from libcst._parser._types.config import AutoConfig, ParserConfig, PartialParserConfig +from libcst._parser._types.token import Token +from libcst._parser._wrapped_tokenize import tokenize_lines _INDENT: TokenType = PythonTokenTypes.INDENT diff --git a/libcst/parser/_entrypoints.py b/libcst/_parser/_entrypoints.py similarity index 91% rename from libcst/parser/_entrypoints.py rename to libcst/_parser/_entrypoints.py index 70fc0702..a4b04879 100644 --- a/libcst/parser/_entrypoints.py +++ b/libcst/_parser/_entrypoints.py @@ -16,10 +16,10 @@ from libcst._nodes._base import CSTNode from libcst._nodes._expression import BaseExpression from libcst._nodes._module import Module from libcst._nodes._statement import BaseCompoundStatement, SimpleStatementLine -from libcst.parser._detect_config import detect_config -from libcst.parser._grammar import get_grammar, validate_grammar -from libcst.parser._python_parser import PythonCSTParser -from libcst.parser._types.config import PartialParserConfig +from libcst._parser._detect_config import detect_config +from libcst._parser._grammar import get_grammar, validate_grammar +from libcst._parser._python_parser import PythonCSTParser +from libcst._parser._types.config import PartialParserConfig _CSTNodeT = TypeVar("_CSTNodeT", bound=CSTNode) diff --git a/libcst/parser/_grammar.py b/libcst/_parser/_grammar.py similarity index 94% rename from libcst/parser/_grammar.py rename to libcst/_parser/_grammar.py index b166f9b2..ad3b5aec 100644 --- a/libcst/parser/_grammar.py +++ b/libcst/_parser/_grammar.py @@ -11,7 +11,7 @@ from typing import Iterator, Mapping, Tuple from parso.pgen2.generator import Grammar, generate_grammar from parso.python.token import PythonTokenTypes, TokenType -from libcst.parser._conversions.expression import ( +from libcst._parser._conversions.expression import ( convert_arg_assign_comp_for, convert_arglist, convert_argument, @@ -60,15 +60,15 @@ from libcst.parser._conversions.expression import ( convert_yield_arg, convert_yield_expr, ) -from libcst.parser._conversions.module import convert_file_input -from libcst.parser._conversions.params import ( +from libcst._parser._conversions.module import convert_file_input +from libcst._parser._conversions.params import ( convert_argslist, convert_fpdef, convert_fpdef_assign, convert_fpdef_star, convert_fpdef_starstar, ) -from libcst.parser._conversions.statement import ( +from libcst._parser._conversions.statement import ( convert_annassign, convert_assert_stmt, convert_assign, @@ -119,7 +119,7 @@ from libcst.parser._conversions.statement import ( convert_with_item, convert_with_stmt, ) -from libcst.parser._conversions.terminals import ( +from libcst._parser._conversions.terminals import ( convert_DEDENT, convert_ENDMARKER, convert_FSTRING_END, @@ -132,9 +132,9 @@ from libcst.parser._conversions.terminals import ( convert_OP, convert_STRING, ) -from libcst.parser._production_decorator import get_productions -from libcst.parser._types.conversions import NonterminalConversion, TerminalConversion -from libcst.parser._types.production import Production +from libcst._parser._production_decorator import get_productions +from libcst._parser._types.conversions import NonterminalConversion, TerminalConversion +from libcst._parser._types.production import Production # Keep this sorted alphabetically diff --git a/libcst/parser/_production_decorator.py b/libcst/_parser/_production_decorator.py similarity index 92% rename from libcst/parser/_production_decorator.py rename to libcst/_parser/_production_decorator.py index b0d81382..3c2c5454 100644 --- a/libcst/parser/_production_decorator.py +++ b/libcst/_parser/_production_decorator.py @@ -6,8 +6,8 @@ # pyre-strict from typing import Callable, Iterable, TypeVar -from libcst.parser._types.conversions import NonterminalConversion -from libcst.parser._types.production import Production +from libcst._parser._types.conversions import NonterminalConversion +from libcst._parser._types.production import Production _NonterminalConversionT = TypeVar( diff --git a/libcst/parser/_python_parser.py b/libcst/_parser/_python_parser.py similarity index 80% rename from libcst/parser/_python_parser.py rename to libcst/_parser/_python_parser.py index daca5800..aea8836d 100644 --- a/libcst/parser/_python_parser.py +++ b/libcst/_parser/_python_parser.py @@ -8,11 +8,14 @@ from typing import Any, Iterable, Mapping, Sequence from parso.pgen2.generator import Grammar from parso.python.token import TokenType -from libcst.parser._base_parser import BaseParser -from libcst.parser._grammar import get_nonterminal_conversions, get_terminal_conversions -from libcst.parser._types.config import ParserConfig -from libcst.parser._types.conversions import NonterminalConversion, TerminalConversion -from libcst.parser._types.token import Token +from libcst._parser._base_parser import BaseParser +from libcst._parser._grammar import ( + get_nonterminal_conversions, + get_terminal_conversions, +) +from libcst._parser._types.config import ParserConfig +from libcst._parser._types.conversions import NonterminalConversion, TerminalConversion +from libcst._parser._types.token import Token class PythonCSTParser(BaseParser[Token, TokenType, Any]): diff --git a/libcst/parser/_types/__init__.py b/libcst/_parser/_types/__init__.py similarity index 100% rename from libcst/parser/_types/__init__.py rename to libcst/_parser/_types/__init__.py diff --git a/libcst/parser/_types/config.py b/libcst/_parser/_types/config.py similarity index 100% rename from libcst/parser/_types/config.py rename to libcst/_parser/_types/config.py diff --git a/libcst/parser/_types/conversions.py b/libcst/_parser/_types/conversions.py similarity index 77% rename from libcst/parser/_types/conversions.py rename to libcst/_parser/_types/conversions.py index 82b4a580..f3303085 100644 --- a/libcst/parser/_types/conversions.py +++ b/libcst/_parser/_types/conversions.py @@ -5,8 +5,8 @@ from typing import Any, Callable, Sequence -from libcst.parser._types.config import ParserConfig -from libcst.parser._types.token import Token +from libcst._parser._types.config import ParserConfig +from libcst._parser._types.token import Token NonterminalConversion = Callable[[ParserConfig, Sequence[Any]], Any] diff --git a/libcst/parser/_types/partials.py b/libcst/_parser/_types/partials.py similarity index 97% rename from libcst/parser/_types/partials.py rename to libcst/_parser/_types/partials.py index 7989444f..166b6d22 100644 --- a/libcst/parser/_types/partials.py +++ b/libcst/_parser/_types/partials.py @@ -28,7 +28,7 @@ from libcst._nodes._expression import ( from libcst._nodes._op import AssignEqual, BaseAugOp, Colon, Dot from libcst._nodes._statement import AsName, BaseSmallStatement, Decorator, ImportAlias from libcst._nodes._whitespace import EmptyLine, SimpleWhitespace, TrailingWhitespace -from libcst.parser._types.whitespace_state import WhitespaceState +from libcst._parser._types.whitespace_state import WhitespaceState _T = TypeVar("_T") diff --git a/libcst/parser/_types/production.py b/libcst/_parser/_types/production.py similarity index 100% rename from libcst/parser/_types/production.py rename to libcst/_parser/_types/production.py diff --git a/libcst/parser/_types/tests/__init__.py b/libcst/_parser/_types/tests/__init__.py similarity index 100% rename from libcst/parser/_types/tests/__init__.py rename to libcst/_parser/_types/tests/__init__.py diff --git a/libcst/parser/_types/tests/test_config.py b/libcst/_parser/_types/tests/test_config.py similarity index 96% rename from libcst/parser/_types/tests/test_config.py rename to libcst/_parser/_types/tests/test_config.py index b108e08b..15217f3c 100644 --- a/libcst/parser/_types/tests/test_config.py +++ b/libcst/_parser/_types/tests/test_config.py @@ -6,7 +6,7 @@ # pyre-strict from typing import Callable -from libcst.parser._types.config import PartialParserConfig +from libcst._parser._types.config import PartialParserConfig from libcst.testing.utils import UnitTest, data_provider diff --git a/libcst/parser/_types/token.py b/libcst/_parser/_types/token.py similarity index 92% rename from libcst/parser/_types/token.py rename to libcst/_parser/_types/token.py index da183db6..b8b9d21f 100644 --- a/libcst/parser/_types/token.py +++ b/libcst/_parser/_types/token.py @@ -11,7 +11,7 @@ from typing import Optional, Tuple from parso.python.token import TokenType from libcst._add_slots import add_slots -from libcst.parser._types.whitespace_state import WhitespaceState +from libcst._parser._types.whitespace_state import WhitespaceState @add_slots diff --git a/libcst/parser/_types/whitespace_state.py b/libcst/_parser/_types/whitespace_state.py similarity index 100% rename from libcst/parser/_types/whitespace_state.py rename to libcst/_parser/_types/whitespace_state.py diff --git a/libcst/parser/_whitespace_parser.py b/libcst/_parser/_whitespace_parser.py similarity index 98% rename from libcst/parser/_whitespace_parser.py rename to libcst/_parser/_whitespace_parser.py index a220cb60..2d0cee7f 100644 --- a/libcst/parser/_whitespace_parser.py +++ b/libcst/_parser/_whitespace_parser.py @@ -29,8 +29,8 @@ from libcst._nodes._whitespace import ( SimpleWhitespace, TrailingWhitespace, ) -from libcst.parser._types.config import BaseWhitespaceParserConfig -from libcst.parser._types.whitespace_state import WhitespaceState as State +from libcst._parser._types.config import BaseWhitespaceParserConfig +from libcst._parser._types.whitespace_state import WhitespaceState as State # BEGIN PARSER ENTRYPOINTS diff --git a/libcst/parser/_wrapped_tokenize.py b/libcst/_parser/_wrapped_tokenize.py similarity index 98% rename from libcst/parser/_wrapped_tokenize.py rename to libcst/_parser/_wrapped_tokenize.py index a793da26..05a63be5 100644 --- a/libcst/parser/_wrapped_tokenize.py +++ b/libcst/_parser/_wrapped_tokenize.py @@ -34,8 +34,8 @@ from parso.utils import PythonVersionInfo, split_lines from libcst._add_slots import add_slots from libcst._exceptions import ParserSyntaxError -from libcst.parser._types.token import Token -from libcst.parser._types.whitespace_state import WhitespaceState +from libcst._parser._types.token import Token +from libcst._parser._types.whitespace_state import WhitespaceState _ERRORTOKEN: TokenType = PythonTokenTypes.ERRORTOKEN diff --git a/libcst/parser/tests/__init__.py b/libcst/_parser/tests/__init__.py similarity index 100% rename from libcst/parser/tests/__init__.py rename to libcst/_parser/tests/__init__.py diff --git a/libcst/parser/tests/test_detect_config.py b/libcst/_parser/tests/test_detect_config.py similarity index 98% rename from libcst/parser/tests/test_detect_config.py rename to libcst/_parser/tests/test_detect_config.py index 2faefe8a..d060f54a 100644 --- a/libcst/parser/tests/test_detect_config.py +++ b/libcst/_parser/tests/test_detect_config.py @@ -6,8 +6,8 @@ # pyre-strict from typing import Union -from libcst.parser._detect_config import detect_config -from libcst.parser._types.config import ParserConfig, PartialParserConfig +from libcst._parser._detect_config import detect_config +from libcst._parser._types.config import ParserConfig, PartialParserConfig from libcst.testing.utils import UnitTest, data_provider diff --git a/libcst/parser/tests/test_footer_behavior.py b/libcst/_parser/tests/test_footer_behavior.py similarity index 100% rename from libcst/parser/tests/test_footer_behavior.py rename to libcst/_parser/tests/test_footer_behavior.py diff --git a/libcst/parser/tests/test_whitespace_parser.py b/libcst/_parser/tests/test_whitespace_parser.py similarity index 98% rename from libcst/parser/tests/test_whitespace_parser.py rename to libcst/_parser/tests/test_whitespace_parser.py index 4792f262..2a19a737 100644 --- a/libcst/parser/tests/test_whitespace_parser.py +++ b/libcst/_parser/tests/test_whitespace_parser.py @@ -9,9 +9,9 @@ from typing import Callable, Sequence, TypeVar import libcst as cst from libcst._nodes._deep_equals import deep_equals -from libcst.parser._types.config import BaseWhitespaceParserConfig -from libcst.parser._types.whitespace_state import WhitespaceState as State -from libcst.parser._whitespace_parser import ( +from libcst._parser._types.config import BaseWhitespaceParserConfig +from libcst._parser._types.whitespace_state import WhitespaceState as State +from libcst._parser._whitespace_parser import ( parse_empty_lines, parse_simple_whitespace, parse_trailing_whitespace, diff --git a/libcst/parser/tests/test_wrapped_tokenize.py b/libcst/_parser/tests/test_wrapped_tokenize.py similarity index 98% rename from libcst/parser/tests/test_wrapped_tokenize.py rename to libcst/_parser/tests/test_wrapped_tokenize.py index 479892fe..9bf7fe98 100644 --- a/libcst/parser/tests/test_wrapped_tokenize.py +++ b/libcst/_parser/tests/test_wrapped_tokenize.py @@ -9,8 +9,8 @@ from parso.python.token import PythonTokenTypes from parso.utils import parse_version_string from libcst._exceptions import ParserSyntaxError -from libcst.parser._types.whitespace_state import WhitespaceState -from libcst.parser._wrapped_tokenize import Token, tokenize +from libcst._parser._types.whitespace_state import WhitespaceState +from libcst._parser._wrapped_tokenize import Token, tokenize from libcst.testing.utils import UnitTest, data_provider