Skip to content

Commit 5b559d9

Browse files
committed
Guess likely type for unknown Match attributes.
1 parent a90aa27 commit 5b559d9

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎language_tool/__init__.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ def get_replacement_list(string, sep="#"):
8585
return string.split(sep) if string else []
8686

8787

88+
def auto_type(string):
89+
try:
90+
return int(string)
91+
except ValueError:
92+
try:
93+
return float(string)
94+
except ValueError:
95+
return string
96+
97+
8898
@total_ordering
8999
class Match:
90100
"""Hold information about where a rule matches text.
@@ -145,6 +155,8 @@ def __iter__(self):
145155
def __setattr__(self, name, value):
146156
if name in self._SLOTS:
147157
value = self._SLOTS[name](value)
158+
else:
159+
value = auto_type(value)
148160
super().__setattr__(name, value)
149161

150162
def __getattr__(self, name):

0 commit comments

Comments
 (0)