Skip to content
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

Syntax parser issues - import #304

Closed
dumblob opened this issue May 3, 2019 · 3 comments
Closed

Syntax parser issues - import #304

dumblob opened this issue May 3, 2019 · 3 comments
Labels

Comments

@dumblob
Copy link

dumblob commented May 3, 2019

I'm trying pytype as an alternative static type checker and it looks quite promising, but the following seems to be quite unpleasant (everything is Python 3.7.3 in a virtual Python environment with pytype installed using pip just for this virtual environment):

from flask import mno, pqr,
    stu, vwx  # type: ignore

This wrong Python syntax is totally OK according to pytype (pytype main.py). It's even worse - pytype then ignores the whole rest of the file in which these 2 lines reside 😮.

from flask import mno, pqr, \
    stu, vwx  # type: ignore

This confuses pytype to write out pretty "random" (unrelated) messages like

File "/home/user00/test00/main.py", line 5, in <module>: Couldn't import pyi for 'flask' [pyi-error]
    File: "/home/user00/test00/env00/lib/python3.7/site-packages/pytype/typeshed/third_party/2and3/click/core.pyi", line 32
      b'def augment_usage_errors('
      ^
  ParseError: Decorator contextmanager not supported
@rchen152
Copy link
Contributor

rchen152 commented May 5, 2019

Thanks for the report! Looks like there are two things going on here.

  1. For
from flask import mno, pqr,
    stu, vwx  # type: ignore

the # type: ignore makes pytype ignore the syntax error on that line, and the syntax error causes pytype to abort early. Hence no error messages anywhere in the source file. The way to fix this issue would probably be to detect when a syntax error is silenced, and print a warning that the file isn't being type-checked.

  1. For
from flask import mno, pqr, \
    stu, vwx  # type: ignore

the pyi error is caused by #171 - pytype can't handle some third party type stubs. (I'm planning to tackle this issue during the PyCon development sprints starting Monday.) Two possible workarounds are to put # pytype: disable=pyi-error on the first line of the import statement or to run pytype with --disable=pyi-error (which can also be put in a pytype section in setup.cfg).

@rchen152 rchen152 added the bug label May 5, 2019
@rchen152
Copy link
Contributor

Closing this issue as # type: ignore no longer appears to silence compiler errors.

@dumblob
Copy link
Author

dumblob commented Jan 11, 2021

Thanks! Will take a look at that sooner or later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants