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

Override --skipunannotated in file comment #4303

Closed
smackesey opened this issue Dec 9, 2022 · 9 comments
Closed

Override --skipunannotated in file comment #4303

smackesey opened this issue Dec 9, 2022 · 9 comments
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request

Comments

@smackesey
Copy link

smackesey commented Dec 9, 2022

Is your feature request related to a problem? Please describe.

We are working to transition our CI from mypy to pyright. Mypy skips unannotated functions by default. pyright can skip unannotated functions if you pass the command line flag --skipunannotated.

Given the current state of the codebase, we're going to need to start off by running CI pyright in --skipunannotated mode in order to pass. We'd then like to opt individual files out of --skipunannotated mode using # pyright: comments at the top of the file.

AFAICT, this is not currently possible. While pyright offers the ability to set the ruleset (off, basic, strict) and any configuration option listed here using a comment, there doesn't appear to be any option corresponding to the command line --skipunannotated switch. Also, I tried using # pyright: basic and that does not override --skipunannotated either.

I also grepped the pyright repo and found that --skipunannotated was setting an analyzeUnannotatedFunctions option. However, # pyright: analyzeUnannotatedFunctions=true did not work to turn off --skipunannotated for a file.

Describe the solution you'd like

Provide a # pyright: setting you can put at the top of a file to turn off --skipunannotated mode for that file.

@smackesey smackesey added the enhancement request New feature or request label Dec 9, 2022
erictraut pushed a commit that referenced this issue Dec 9, 2022
… corresponds to the `--skipunannotated` command-line option. Added an information diagnostic for skipped functions. This addresses #4303.
@erictraut
Copy link
Collaborator

This is a reasonable feature request. When I initially added the --skipunannotated command-line option, it was mainly a performance optimization to do apples-to-apples comparisons against mypy, but I can see some utility in exposing it as a full-fledged configuration option. The next release will include support for analyzeUnannotatedFunctions. The command-line flag will still be present and will override the configuration setting if specified. File-level overrides using # pyright comments will also be supported.

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Dec 9, 2022
@smackesey
Copy link
Author

The command-line flag will still be present and will override the configuration setting if specified.

Will there be (or is there already) a negative form of the command-line flag, i.e. --no-skipunannotated?

@erictraut
Copy link
Collaborator

No, there's no negative form. If you want pyright's default behavior, just omit the --skipunannotated command-line flag.

@erictraut
Copy link
Collaborator

This is included in pyright 1.1.284, which I just published. It will also be included in a future release of pylance.

@smackesey
Copy link
Author

smackesey commented Dec 14, 2022

Thank you for implementing this. I just tried it out, and it works, but now pyright's output on our codebase contains an enormous number of lines like this:

information: Analysis of function "test_memoization_k8s_executor" is skipped because it unannotated

The standard way to suppress this would be to set the reportXXX setting to none, but there doesn't appear to be any setting for analyzeUnannotatedFunctions, which just takes a boolean (I tried analyzeUnannotatedFunctions = "none" in config, that was an error.

Is there any way to suppress these messages with pyright (for now I'm using --outputjson)? It makes the default CLI output of pyright useless on our codebase (64 errors, 37 warnings, 15319 informations), and will do the same for anyone who turns on this feature with a lot of unannotated functions.

@erictraut
Copy link
Collaborator

If you have specialized needs for the output, you can wrap pyright with a small script that invokes it with --outputjson. The script can then easily filter or format the output as you see fit.

@smackesey
Copy link
Author

specialized needs

Given that analyzeUnannotatedFunctions is now a config option, I wouldn't call these needs "specialized". Anyone setting analyzeUnannotatedFunctions=false is likely doing so because they have many unannotated functions in their codebase. And if they have many of those functions, pyright's default output becomes mostly useless. That said, I am currently doing as you describe with a wrapper script and it works OK.

@erictraut
Copy link
Collaborator

You commented on this feature request which has gathered some additional support since it was first posted. I think it's worth revisiting that feature request and adding a --level command-line option to filter diagnostics below a certain level of severity. Would that meet your needs here?

@smackesey
Copy link
Author

I think it's worth revisiting that feature request and adding a --level command-line option to filter diagnostics below a certain level of severity. Would that meet your needs here?

100%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants