Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Fix col offset #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions flake8_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,22 @@ def run(self) -> Iterator[_Flake8Error]:
# unexpected clashes with other .py and .pyi files in the same original
# directory.
with TemporaryDirectory(prefix='flake8mypy_') as d:
with NamedTemporaryFile(
'w', encoding='utf8', prefix='tmpmypy_', suffix='.py', dir=d
) as f:
self.filename = f.name
file = NamedTemporaryFile(
'w',
encoding='utf8',
prefix='tmpmypy_',
suffix='.py',
dir=d,
delete=False,
)
try:
self.filename = file.name
for line in self.lines:
f.write(line)
f.flush()
file.write(line)
file.close()
yield from self._run()
finally:
os.remove(file.name)

def _run(self) -> Iterator[_Flake8Error]:
mypy_cmdline = self.build_mypy_cmdline(self.filename, self.options.mypy_config)
Expand Down Expand Up @@ -255,7 +263,7 @@ def make_error(self, line: str, regex: Pattern) -> Error:
raise ValueError("unmatched line")

lineno = int(m.group('lineno'))
column = int(m.group('column') or 0)
column = int(m.group('column') or 1) - 1
message = m.group('message').strip()
if m.group('class') == 'note':
return T400(lineno, column, vars=(message,))
Expand All @@ -279,7 +287,7 @@ def build_mypy_re(self, filename: Union[str, Path]) -> Pattern:
except ValueError:
pass # not relative to the cwd

re_filename = str(filename).replace('.', r'\.')
re_filename = re.escape(str(filename))
if re_filename.startswith(r'\./'):
re_filename = re_filename[3:]
return re.compile(
Expand Down