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

Python longstring tag vs block comment tag in Vscode #23703

Open
Apamobil opened this issue Jun 12, 2024 · 7 comments
Open

Python longstring tag vs block comment tag in Vscode #23703

Apamobil opened this issue Jun 12, 2024 · 7 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team

Comments

@Apamobil
Copy link

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.85.1
  • OS Version: MS Windows 11 enterprise

DESCRIPTION

Vscode Language Configuration includes either line comment tag and or block comment tags. The extension we have been developing uses by default (based on implementation decision) block comments if they exist for the programming/script language of the current file.

The problem is with Python block comments and Vscode. Vscode misleadingly returns longstring tag ''' as a block comment tag that must be used in the beginning and end of a multi-line comment. However, according to the Python language specification the longstring tag is NOT for comments, but for long strings (as its name states).

From Python language reference:

2.1.3. Comments
2.4.1. String and Bytes literals

It seems this is a bug in Vscode implementation. It should be corrected in a way that so that language configuration does not contain longer longstring tag (''') as a block comment tag for Python comment.

@vscodenpa
Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.90.0. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@Apamobil
Copy link
Author

It's not yet available due to the company policy.

@vscodenpa vscodenpa added the triage-needed Needs assignment to the proper sub-team label Jun 12, 2024
@bhavyaus bhavyaus assigned mjbvz and unassigned bhavyaus Jun 14, 2024
@vscodenpa vscodenpa removed the triage-needed Needs assignment to the proper sub-team label Jun 14, 2024
@mjbvz mjbvz assigned luabud and unassigned mjbvz Jun 17, 2024
@luabud
Copy link
Member

luabud commented Jun 17, 2024

Hi @Apamobil, I am struggling to reproduce any wrong behaviour in VS Code with longstrings defined by ''' or with comment blocks, with the Pylance extension disabled or enabled. Would you mind explaining a bit better what is the behaviour you are experiencing?

@Apamobil
Copy link
Author

Hi! In a nutshell:

Vscode misleadingly returns longstring tag ''' as a block comment tag for Python.

According to the Python language specification longstring tag is not intended for comments, but for long strings as the name states. This is often used as an alternative method for commenting out multiple lines (using triple-quoted string literals (''' ''' or """ """). However, they are not officially block comments for Python.

The problem is that automated formatters and linters don't like the longstring tags and are sometimes formatting the comments marked with longstring tags.

See also this article, it gives some background info about commenting in Python: https://www.datacamp.com/tutorial/python-block-comment

@luabud luabud transferred this issue from microsoft/vscode Jun 26, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jun 26, 2024
@luabud
Copy link
Member

luabud commented Jun 26, 2024

@Apamobil would you mind explaining what you mean by "VS Code returns a longstring tag as a block comment tag"?

The reason why I'm not following what's happening is that the rendering of comments blocks with # and ''' or """ are treated differently in VS Code. In the screenshot below, the comment blocks are grayed out, while the string blocks (whether in a string assignment or not) are displayed with a different color:

Image

But perhaps the problem isn't with VS Code itself but with a linter or formatter extension you're using?

@karthiknadig karthiknadig self-assigned this Jun 26, 2024
@Apamobil
Copy link
Author

I'm also a bit on a thin ice here myself since the colleague who reported this behavior is on a leave and I wrote this ticket on behalf of him.

I think the problem is that Vscode LanguageConfiguration includes either line comment tag and or block comment tags. The extension in question uses by default block comments. The block comments for python are implemented as ''' in Vscode and it is against the python language reference. And this causes problems with linters/formatters.

Does this make it any more clear? :)

@mikavuo
Copy link

mikavuo commented Aug 5, 2024

Hi all,

Because Python language supports only line comment (that is starting with character '#') then it is not right that the Vscode returns from the LanguageConfiguration also a block comment tag, because there does not exist such thing in Python language. Reference: https://docs.python.org/3/reference/lexical_analysis.html#comments

Now that we know that LanguageConfiguration shall not contain a value for Python block comment it should be fixed to not contain the block comment tag value.

We have real issues related to this and hope that this would be fixed to make behaviour compliant with the official Python language reference.

Thanks for anyone reading this :)

@karthiknadig karthiknadig added the bug Issue identified by VS Code Team member as probable bug label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

7 participants