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

docstring code formatter: emit warning messages when code snippets fail to format #8856

Open
BurntSushi opened this issue Nov 27, 2023 · 3 comments
Labels
docstring Related to docstring linting or formatting formatter Related to the formatter wish Not on the current roadmap; maybe in the future

Comments

@BurntSushi
Copy link
Member

#8811 added initial support for formatting doctest code snippets in docstrings, but it does have some silent behavior that should probably be louder. For example, if it detects a code snippet that is invalid Python, then it will silently skip the code snippet. Another example is a bit more pathological, but it is possible for the code snippet formatter to generate invalid Python in some case (as a result of nested triple quoted strings in some cases). In this case, we detect it and bail out of reformatting the code snippet. Ideally, we would emit a warning about this too, although this is arguably more of a bug in the current implementation.

This was brought up in review, and it was suggested that perhaps we split the warning/logging infrastructure out from the linter and use it in the formatter.

@BurntSushi BurntSushi added docstring Related to docstring linting or formatting formatter Related to the formatter labels Nov 27, 2023
@MichaReiser
Copy link
Member

This was #8811 (comment), and it was suggested that perhaps we split the warning/logging infrastructure out from the linter and use it in the formatter.

I'm a bit hesitant of adopting the linter's warn macros because they assume a CLI client and either mess with stderr if you would call ruff through a python or rust API or are silently ignored in the LSP.

Ideally we would return diagnostics as part of the formatted result and it's the caller's responsibility to present them somehow to the user.

@charliermarsh
Copy link
Member

If we don't think we're going to add diagnostics to the formatter API in the near future, though, warning is not unreasonable IMO.

@BurntSushi BurntSushi added this to the Formatter: Stable milestone Nov 29, 2023
@MichaReiser
Copy link
Member

@BurntSushi are you planning to work on this for the stable release? If not, then I recommend removing it from Stable and mark it as wish (I agree we should do it, but I think we could ship the stable without it)

@BurntSushi BurntSushi removed this from the Formatter: Stable milestone Dec 23, 2023
@BurntSushi BurntSushi added the wish Not on the current roadmap; maybe in the future label Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docstring Related to docstring linting or formatting formatter Related to the formatter wish Not on the current roadmap; maybe in the future
Projects
None yet
Development

No branches or pull requests

3 participants