Skip to content

Commit 1ef84ae

Browse files
refactor: Use general parser.common import for StrRegion and .common
1 parent 2c88d71 commit 1ef84ae

File tree

14 files changed

+22
-15
lines changed

14 files changed

+22
-15
lines changed

parser/common/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .common import *
2+
from .error import * # <^ might add some stuff so `import *`
3+
from .str_region import StrRegion # <-- won't add stuff to str_region so not `import *`
4+
from .tree_print import *

parser/common/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from .str_region import StrRegion
44

5+
__all__ = ['HasRegion', 'RegionUnionArgT', 'region_union']
6+
57

68
class HasRegion:
79
region: StrRegion

parser/common/error.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from .common import HasRegion
1010
from .str_region import StrRegion
1111

12+
__all__ = ['BaseParseError', 'BaseLocatedError']
13+
1214

1315
# We unconditionally add this polyfill to ensure that
1416
# exceptions are always part of str(exc).

parser/common/str_region.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from dataclasses import dataclass
44

5+
__all__ = ['StrRegion']
6+
57

68
@dataclass
79
class StrRegion:

parser/cst/base_node.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
from dataclasses import dataclass, field
44

5-
from ..common.common import HasRegion
6-
from ..common.str_region import StrRegion
5+
from ..common import StrRegion, HasRegion
76
from ..tokens import Token
87

98

parser/cst/named_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from typing import TYPE_CHECKING, overload, Sequence, cast, Literal
55

66
from .base_node import Leaf, AnyNode, Node
7-
from parser.common.str_region import StrRegion
7+
from ..common import StrRegion
88

99
if TYPE_CHECKING:
10-
from parser.tokens import Token
10+
from ..tokens import Token
1111

1212

1313
# NOTE: these classes only follow the Liskov substitution principle on

parser/cst/treegen.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
from .named_node import AnyNamedNode, node_from_token, node_cls_from_name
77
from .nodes import *
88
from .token_matcher import OpM, KwdM, Matcher, PatternT
9-
from ..common.common import region_union, RegionUnionArgT
9+
from ..common import StrRegion, region_union, RegionUnionArgT
1010
from ..common.error import BaseParseError, BaseLocatedError
11-
from ..common.str_region import StrRegion
1211
from ..lexer import Tokenizer
1312
from ..operators import UNARY_OPS, COMPARISONS, ASSIGN_OPS
1413
from ..tokens import *

parser/lexer/tokenizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
SemicolonToken, AttrNameToken, IdentNameToken,
1212
GETATTR_VALID_AFTER_CLS, EofToken
1313
)
14+
from ..common import StrRegion
1415
from ..common.error import BaseParseError, BaseLocatedError
15-
from ..common.str_region import StrRegion
1616
from ..operators import OPS_SET, MAX_OP_LEN, OP_FIRST_CHARS
1717

1818
if TYPE_CHECKING:

parser/lexer/tokens.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from enum import Enum
55
from typing import Union, Callable, TYPE_CHECKING
66

7-
from ..common.str_region import HasRegion
8-
from ..common.str_region import StrRegion
7+
from ..common import HasRegion, StrRegion
98

109
__all__ = [
1110
'AnyCommentToken', 'AnyNameToken', 'AttrNameToken', 'BlockCommentToken',

test/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from enum import IntFlag, Enum
66
from typing import Sequence, TypeVar
77

8-
from parser.cst.base_node import Leaf, AnyNode, Node
8+
from parser.common.error import BaseParseError
99
from parser.common.tree_print import tformat
10+
from parser.cst.base_node import Leaf, AnyNode, Node
1011
from parser.cst.treegen import TreeGen, CstParseError
11-
from parser.common.error import BaseParseError
1212
from parser.lexer import Tokenizer
1313
from parser.lexer.tokens import Token, OpToken
1414
from test.snapshottest import SnapshotTestCase

0 commit comments

Comments
 (0)