hauntsaninja / mypy_primer

Run mypy and pyright over millions of lines of code
MIT License
55 stars 29 forks source link

Make primer work on Windows again #99

Closed AlexWaygood closed 9 months ago

AlexWaygood commented 9 months ago

I set out to figure out why the changes I made in #97 caused primer to hang in typeshed's CI, but quickly realised that I couldn't run primer locally at all any more! This is because shlex.quote() does the wrong thing on Windows when you pass it a path. All you actually need to do on Windows to quote a path is to do some basic validation and then surround it with "", so there's a pretty simple workaround.

AlexWaygood commented 9 months ago

Is the issue that shlex.quote prefers single quotes instead of double quotes?

I think that's the main issue, yeah, though I don't really know much more than what the warning in the docs tells me.

This solution is derived from Eryk Sun's comments on a Stack Overflow question that suggest that this should always do the right thing if all you need to do is to quote a Windows path, and it was the quoting of paths that was causing me grief locally.

An alternative solution would be to use subprocess.list2cmdline, which I think tries harder to capture all the semantics of the Windows command line. I didn't go for that because:

  1. Not sure we need it here
  2. It's undocumented
  3. There was some scepticism recently when people suggested documenting it that makes me nervous about using it: https://discuss.python.org/t/why-is-subprocess-list2cmdline-not-documented/25044/1