-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Description
Does this issue occur when all extensions are disabled?: Yes/No
- VS Code Version: Code 1.79.0 (b380da4, 2023-06-07T14:26:35.552Z)
- OS Version: Windows_NT x64 10.0.22621
Steps to Reproduce:
- Update to 1.79.0. Use any bundled theme.
- Open any Python file with docstring (or copy-paste the example below). All docstrings are rendered in the same style as comments.
Related Issue/PR
- The issue that proposed the change: Python multi-line comment strings should be treated as comments in all themes #182163
- Yes, as the title suggests, for multi-line comment strings, I agree they should be treated as comments because they are "multi-line comment strings".
- The PR that did the change: all color themes: treat comment docstrings as comments too #182162
- I'm against this change as it actually swapped the concept: the title now mentions docstrings, and it does affect all docstrings instead of only "multi-line comment strings".
From Python Docs
docstring
A string literal which appears as the first expression in a class, function or module. While ignored when the suite is executed, it is recognized by the compiler and put into the__doc__attribute of the enclosing class, function or module. Since it is available via introspection, it is the canonical place for documentation of the object.
Takeaway of the above:
- docstring is a Python language feature associated with the dunder attribute
__doc__. It is NOT a comment. - Not every string literal is a docstring. Only those that appear as the 1st statement of a scope are docstrings.
Therefore, I think the current behaviour is WRONG as docstrings are not comments, but I agree with issue #182163 that comment strings should be rendered as comments.
Additional context
The Python extension additionally treats some non-docstring strings similar to a docstring, like the B and e in this example:
class A:
"""This is the docstring for A. Shown on hover."""
B = 1
"""Shown on hover for B."""
def c(self, x:int)->int:
"""This is the docstring for c. Shown on hover."""
d = 1
"""This is nothing but a comment.""" # pylint: pointless-string-statement / W0105
e = 1
"""Shown on hover for e."""Hovering on A B c e will all show the respective string content in VSCode. However, for B and e they're actually not docstrings, but it's indeed useful if we can add some "doc"strings for global variables and class attributes.
Also, some linters, e.g. pylint, share the same way to interpret these string literals: pylint generates a pointless-string-statement warning only on the "comment", but not at the other 4 places.
Thus, a better solution could be to expose extra rendering tokens and let the Python extension decide whether each string literal should be treated as a docstring or a comment string.
Finally, many thanks to everyone who has participated in the fruitful discussion in #182162 (cc @ElectricRCAircraftGuy @aeschli @k98kurz @starball5 @torext @dbaeumer). Further comments are welcomed.