Skip to content

Multi-line -c flag doesn't work on Windows #2269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
evhub opened this issue Oct 17, 2016 · 10 comments
Closed

Multi-line -c flag doesn't work on Windows #2269

evhub opened this issue Oct 17, 2016 · 10 comments
Labels
bug mypy got something wrong priority-2-low

Comments

@evhub
Copy link
Contributor

evhub commented Oct 17, 2016

Simplest reproduction seems to be

mypy -c '
a = 5  # type: str'

which does not produce any errors, despite the fact that a is clearly incorrectly typed. The similar

mypy -c 'a = 5  # type: str'

however, does show an error, which seems to indicate that the first behavior is definitely a bug.

@ddfisher
Copy link
Collaborator

Strange, that's not the case for me:

$ python3 -m mypy -c '
a = 5  # type: str'
<string>:2: error: Incompatible types in assignment (expression has type "int", variable has type "str")

@evhub
Copy link
Contributor Author

evhub commented Oct 17, 2016

@ddfisher Strange. I'm running mypy 0.4.5 on Python 3.5.1 and Windows 10. My console log is:

C:\Users\Evan\Documents\GitHub> mypy -c '
>> a = 5  # type: str'
>>
C:\Users\Evan\Documents\GitHub> mypy -c 'a = 5  # type: str'
<string>:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")

@ddfisher
Copy link
Collaborator

Hmm. Mine is on mypy 0.4.5; Python 3.5.2; OS X 10.11. Is it possible your terminal is removing the comment?

Maybe try:

echo '
a = 5  # type: str'

and

mypy -c '
a = "foo" 
a = 5'

@gvanrossum
Copy link
Member

@evhub If you can put a print() statement in mypy to confirm the string argument it is receiving that might shed light on the matter. It is likely some odd interaction with the Windows shell. I wonder if there's a CRLF vs. LF issue? E.g.

diff --git a/mypy/main.py b/mypy/main.py
index bbc3002..8a87e05 100644
--- a/mypy/main.py
+++ b/mypy/main.py
@@ -314,6 +314,7 @@ def process_options(args: List[str],
             fail("Can't find package '{}'".format(special_opts.package))
         return targets, options
     elif special_opts.command:
+        print(repr(special_opts.command))
         options.build_type = BuildType.PROGRAM_TEXT
         return [BuildSource(None, None, '\n'.join(special_opts.command))], options

@evhub
Copy link
Contributor Author

evhub commented Oct 17, 2016

@ddfisher The echo output includes the comment, so I don't think that's the issue.
@gvanrossum A CRLF vs. LF issue seems plausible, especially since I just tried it on the Ubuntu subsystem for Windows and it worked just fine. Adding your print statement shows that MyPy seems to only be receiving the first line, which is consistent with the behavior I'm experiencing:

C:\Users\Evan\Documents\GitHub> mypy -c '#first line
>> a = 5  # type: str'
>>
['#first line']

@gvanrossum
Copy link
Member

gvanrossum commented Oct 17, 2016 via email

@evhub
Copy link
Contributor Author

evhub commented Oct 17, 2016

@gvanrossum Did a little bit of research, and it looks like this is just an inherit issue with cmd.exe. I couldn't replicate this in any of my own installed Python scripts, though, so I looked around a bit and it seems that setuptools provides a way to get around this by setting console_scripts in entry_points, but since MyPy installs itself by setting scripts directly, it doesn't work.

@gvanrossum gvanrossum changed the title Multi-line code snippets not type-checked Multi-line -c flag doesn't work on Windows Oct 18, 2016
@gvanrossum
Copy link
Member

See also #1226.

As a work around you can use multiple -c flags: mypy -c '' -c 'a = 5 # type: str'.

@gvanrossum gvanrossum added the bug mypy got something wrong label Oct 18, 2016
@gvanrossum gvanrossum added this to the Future milestone Oct 18, 2016
@evhub
Copy link
Contributor Author

evhub commented Oct 18, 2016

@gvanrossum Great, thanks! It seems like calling python -m mypy instead of calling mypy directly also works, and then there's no need for multiple -c invocations.

@gvanrossum gvanrossum removed this from the Future milestone Mar 29, 2017
@emmatyping
Copy link
Member

I believe this is fixed, as we now use console_scripts to install mypy, meaning we aren't hit by the batch file issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-2-low
Projects
None yet
Development

No branches or pull requests

4 participants