Skip to content

Commit 2814397

Browse files
committed
Lines read from readlines() have line terminators.
1 parent 86645ba commit 2814397

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎language_tool/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ class Match:
8888
_SLOTS = ("fromy", "fromx", "toy", "tox", "frompos", "topos",
8989
"ruleId", "subId", "msg", "replacements",
9090
"context", "contextoffset", "errorlength")
91+
_INT_SLOTS = {"fromy", "fromx", "toy", "tox", "frompos", "topos"}
9192
_frompos_cache, _topos_cache = None, None
9293

9394
def __init__(self, attrib, text=None):
9495
for k, v in attrib.items():
95-
setattr(self, k, int(v) if v.isdigit() else v)
96+
setattr(self, k, int(v) if k in self._INT_SLOTS else v)
9697
if not isinstance(self.replacements, list):
9798
self.replacements = (self.replacements.split("#")
9899
if self.replacements else [])

‎language_tool/__main__.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_rules(rules: str) -> set:
4343

4444
def get_text(file, encoding):
4545
with open(file, encoding=encoding) as f:
46-
text = "\n".join(f.readlines())
46+
text = "".join(f.readlines())
4747
return text
4848

4949

@@ -98,8 +98,8 @@ def main():
9898
print(lang_tool.correct(text))
9999
else:
100100
print()
101-
for match in lang_tool.check(text):
102-
print(match)
101+
for n, match in enumerate(lang_tool.check(text)):
102+
print("{}.".format(n + 1), match)
103103
print()
104104

105105

0 commit comments

Comments
 (0)