Skip to content

Commit ae00ecf

Browse files
committed
make re patterns private
1 parent bdaadf7 commit ae00ecf

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

tatsu/infos.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import copy
44
import dataclasses
55
import re
6-
from collections.abc import Callable, Mapping
6+
from collections.abc import Callable, MutableMapping
77
from itertools import starmap
88
from typing import Any, NamedTuple
9+
from warnings import warn
910

1011
from .ast import AST
1112
from .tokenizing import Tokenizer
@@ -30,8 +31,8 @@ class ParserConfig:
3031
start_rule: str | None = None # FIXME
3132
rule_name: str | None = None # Backward compatibility
3233

33-
comments_re: re.Pattern | None = None
34-
eol_comments_re: re.Pattern | None = None
34+
_comments_re: re.Pattern | None = dataclasses.field(default=None, init=False, repr=False)
35+
_eol_comments_re: re.Pattern | None = dataclasses.field(default=None, init=False, repr=False)
3536

3637
tokenizercls: type[Tokenizer] | None = None # FIXME
3738
semantics: type | None = None
@@ -64,9 +65,19 @@ def __post_init__(self): # pylint: disable=W0235
6465
if self.ignorecase:
6566
self.keywords = [k.upper() for k in self.keywords]
6667
if self.comments:
67-
self.comments_re = re.compile(self.comments)
68+
self._comments_re = re.compile(self.comments)
6869
if self.eol_comments:
69-
self.eol_comments_re = re.compile(self.eol_comments)
70+
self._eol_comments_re = re.compile(self.eol_comments)
71+
72+
@property
73+
def comments_re(self) -> re.Pattern:
74+
warn(f"{self.__class__.name}.comments_re is deprecated", DeprecationWarning)
75+
return self._comments_re
76+
77+
@property
78+
def eol_comments_re(self) -> re.Pattern:
79+
warn(f"{self.__class__.name}.eol_comments_re is deprecated. Use ", DeprecationWarning)
80+
return self._eol_comments_re
7081

7182
@classmethod
7283
def new(
@@ -84,7 +95,7 @@ def effective_rule_name(self):
8495
# note: there are legacy reasons for this mess
8596
return self.start_rule or self.rule_name or self.start
8697

87-
def _find_common(self, **settings: Any) -> Mapping[str, Any]:
98+
def _find_common(self, **settings: Any) -> MutableMapping[str, Any]:
8899
return {
89100
name: value
90101
for name, value in settings.items()
@@ -103,6 +114,11 @@ def replace_config(
103114

104115
def replace(self, **settings: Any) -> ParserConfig:
105116
overrides = self._find_common(**settings)
117+
for field in [
118+
field.name for field in dataclasses.fields(self) if field.init == False
119+
]:
120+
if field in overrides.keys():
121+
overrides.pop(field)
106122
result = dataclasses.replace(self, **overrides)
107123
if 'grammar' in overrides:
108124
result.name = result.grammar

0 commit comments

Comments
 (0)