1. spirit
  2. language_tool

Commits

spirit  committed d9320f0

Guess likely type for unknown Match attributes.

  • Participants
  • Parent commits b6b077b
  • Branches default

Comments (0)

Files changed (1)

File language_tool/__init__.py

View file
  • Ignore whitespace
     return string.split(sep) if string else []
 
 
+def auto_type(string):
+    try:
+        return int(string)
+    except ValueError:
+        try:
+            return float(string)
+        except ValueError:
+            return string
+
+
 @total_ordering
 class Match:
     """Hold information about where a rule matches text.
     def __setattr__(self, name, value):
         if name in self._SLOTS:
             value = self._SLOTS[name](value)
+        else:
+            value = auto_type(value)
         super().__setattr__(name, value)
 
     def __getattr__(self, name):