pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Suggest inserting `# pyright: ignore` without `enableTypeIgnoreComments`

Open Andrej730 opened this issue 7 months ago • 1 comments

After #4494 quick actions now have an option to insert # pyright: ignore[xxx] instead of generic # type: ignore, which is very useful, especially combined with reportUnnecessaryTypeIgnoreComment = true, so each comment basically becomes a direct typing test.

But, as described in https://github.com/microsoft/pylance-release/issues/5565#issuecomment-1974327350, it only works if pyright's enableTypeIgnoreComments is enabled. If this option is enabled, then # type: ignore have no effect and inserting # pyright: ignore becomes a necessity, makes sense.

The thing is, sometimes you meet a general issue, that any type checker would report, and then # type: ignore does come in handy and enabling enableTypeIgnoreComments is kind of assumes that everyone using a codebase is using pyright only and the only way to get rid of the type error is to double ignore it as shown below, which doesn't look good in general.

foo(bar) # pyright: ignore[reportRedeclaration] # type: ignore

But sometimes you're just working around pyright quirks and inserting # pyright: ignore[xxx] fits the best.

My proposals:

  • add better documentation for the current workflow, to make "enableTypeIgnoreComments" -> "available quick action for inserting pyright ignore comments" connection more discoverable. Which I guess is kind of part of #7163

  • to show both options in Quick Actions, so user could decide what fits the best for the current situation. Though option to insert # type: ignore probably should be hidden if enableTypeIgnoreComments is true, to avoid return of #4494.

Andrej730 avatar May 15 '25 16:05 Andrej730

Thanks for the issue. I agree that the user should have a choice here.

debonte avatar May 24 '25 16:05 debonte

This issue has been fixed in prerelease version 2025.6.101, which we've just released. You can find the changelog here: CHANGELOG.md

rchiodo avatar Jul 03 '25 00:07 rchiodo

Thank you, works a like a charm.

Image

Andrej730 avatar Jul 03 '25 04:07 Andrej730

hello @debonte h

anandpatel2034-cloud avatar Sep 28 '25 09:09 anandpatel2034-cloud