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

Make temp file creation Windows compatible #18

Merged
merged 2 commits into from
Jun 28, 2018
Merged
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
22 changes: 15 additions & 7 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 @@ -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