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

Failure on `# type: ignore[code]' comments #108

Closed
algorythmic opened this issue Jul 14, 2020 · 5 comments
Closed

Failure on `# type: ignore[code]' comments #108

algorythmic opened this issue Jul 14, 2020 · 5 comments
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@algorythmic
Copy link

Environment data

  • Language Server version: 2020.7.1
  • OS and version: macOS 10.15
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.7 from Homebrew

Expected behaviour

# type: ignore[code] treated same as # type: ignore (or, at least, does not generate its own error)

Actual behaviour

A line with e.g. # type: ignore[attr-defined] produces a number of errors:

image
image

Note that Type annotation not supported for this type of expression is reported even if python.analysis.typeCheckingMode is off.

Code Snippet / Additional information

Mypy uses this syntax since 0.730 (python/mypy#7239). See e.g. PyCQA/pyflakes#455 and google/pytype#485 for other tools' changes to adapt to this syntax.

@erictraut
Copy link
Contributor

Thanks for the suggestion. The use of "[code, ...]" after a "# type: ignore" comment is not part of the official spec, but it appears it's a variant supported by mypy. The error codes will not have any meaning outside of mypy, but we could treat it as a general "# type: ignore" (i.e. suppress all errors on the line) as specified in PEP 484.

@erictraut
Copy link
Contributor

This change will be included in the next version of Pylance/Pyright. Thanks again for the suggestion.

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jul 14, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.7.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202072-15-july-2020

@rpatterson
Copy link

I'm unable to get this to work, there's no squigly underline error indication when I add the following to a Python file opened in VSCode:

XXX = YYY  # type: ignore[ZZZ]

But the indication is displayed with the right error code when I remove the entire comment, so the code included in the brackets is having no effect. FWIW, this is also true when using Pyright seperately from Pylance.

Environment data

  • Language Server version: 2021.6.3
  • OS and version: linux x64
  • Python version (and distribution if applicable, e.g. Anaconda):
  • python.analysis.indexing: undefined
  • python.analysis.typeCheckingMode: off

@erictraut
Copy link
Contributor

As mentioned above, the bracket after the # type: ignore is a non-standard proprietary extension used by mypy. The PEP 484 standard specifies only # type: ignore, and that's what pylance supports. If there is a bracket after the # type: ignore, it is ignored. Based on your description, it is working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

4 participants