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

Showing error even if the file runs #219

Closed
Shubham20091999 opened this issue Aug 8, 2020 · 6 comments
Closed

Showing error even if the file runs #219

Shubham20091999 opened this issue Aug 8, 2020 · 6 comments
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@Shubham20091999
Copy link

Environment data

  • Language Server version: 2020.8.0
  • OS and version: Windows 10 2004
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.7

Expected behaviour

Error ("Single close brace not allowed within f-string literal; use double close brace") should not have occured

Actual behaviour

Error occuring at closing brace in {video} in the code provided

image

Logs

[Info  - 5:34:19 pm] No configuration file found.
[Info  - 5:34:19 pm] Setting pythonPath for service "Youtube Downloader": "C:\ProgramData\Miniconda3\python.exe"
[Error - 5:34:19 pm] stubPath d:\Projects\Python\Youtube Downloader\typings is not a valid directory.
[Info  - 5:34:19 pm] Assuming Python version 3.7
[Info  - 5:34:19 pm] Assuming Python platform Windows
[Info  - 5:34:19 pm] Searching for source files
[Info  - 5:34:19 pm] Found 2 source files
[BG] analyzing: d:\Projects\Python\Youtube Downloader\logic.py ...
[BG]   parsing: d:\Projects\Python\Youtube Downloader\logic.py (56ms)
[BG]   parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\2and3\builtins.pyi (71ms)
[BG]   binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\2and3\builtins.pyi (28ms)
[BG]   binding: d:\Projects\Python\Youtube Downloader\logic.py (1ms)
[BG]   checking: d:\Projects\Python\Youtube Downloader\logic.py ...
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\json\__init__.pyi (1ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\json\__init__.pyi (1ms)
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\os\__init__.pyi (10ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\os\__init__.pyi (4ms)
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\subprocess.pyi (5ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\subprocess.pyi (2ms)
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\sys.pyi (6ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\sys.pyi (6ms)
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\typing.pyi (21ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\typing.pyi (5ms)
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\abc.pyi (1ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\abc.pyi (0ms)
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\2and3\_typeshed\__init__.pyi (14ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\2and3\_typeshed\__init__.pyi (0ms)
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\third_party\2and3\typing_extensions.pyi (1ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\third_party\2and3\typing_extensions.pyi (1ms)
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\json\decoder.pyi (1ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\json\decoder.pyi (0ms)
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\posix.pyi (0ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\posix.pyi (1ms)
[BG]     parsing: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\os\path.pyi (6ms)
[BG]     binding: c:\Users\Shubham\.vscode\extensions\ms-python.vscode-pylance-2020.8.0\server\typeshed-fallback\stdlib\3\os\path.pyi (0ms)
[BG]   checking: d:\Projects\Python\Youtube Downloader\logic.py (195ms)
[BG] analyzing: d:\Projects\Python\Youtube Downloader\logic.py (351ms)

Code Snippet / Additional information

os.system(f'''Dependencies\youtube-dl -o "{outLoc}\{video}.%(ext)s" --add-metadata -x --audio-format {ext} "https://www.youtube.com/watch?v={video.id()}">NUL''')
@github-actions github-actions bot added the triage label Aug 8, 2020
@erictraut
Copy link
Contributor

Thanks for the bug report. There is indeed a bug in Pylance here, but there's also a bug in your code. Let me explain.

You are using the backslash in your string in two locations. In Python strings, the backslash character is used to start an escape sequence. It is supposed to be followed by one or more other characters to complete the escape sequence. For example "\n" represents a new-line character and "\048" is an octal escape sequence. A full list of recognized escape sequences can be found in the Python documentation. Escape sequences that are not listed are considered bugs. In the current version of the Python interpreter, these cases are flagged with a deprecation warning, but in future versions they will be rejected as an error. Here's the text from the spec:

Changed in version 3.6: Unrecognized escape sequences produce a DeprecationWarning. In a future Python version they will be a SyntaxWarning and eventually a SyntaxError.

Pylance was incorrectly handling the unrecognized escape sequences found in your string literal. When it saw the backslash, it skipped over the next character. In the case of "{video}", it skipped the open bracket character. I've fixed this problem, and it will be corrected in the next version of Pylance.

The way to fix the bug in your code is to use a double backslash "\" rather than a single backslash.

Pylance contains code to warn you about unrecognized escape sequences, but this diagnostic is suppressed when typeCheckingMode is "off". If you set typeCheckingMode to "basic", you will see a warning for this condition.

@savannahostrowski & @jakebailey , we might consider enabling the reportInvalidStringEscapeSequence diagnostic rule (at "warning" severity level) even when typeCheckingMode is "off". It's a useful diagnostic even for users who are not interested in type checking, and it will not produce false positives. Let me know what you think here.

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Aug 8, 2020
@github-actions github-actions bot removed the triage label Aug 8, 2020
@Shubham20091999
Copy link
Author

Thank You
I had did not know we have to use \ when we use triple quotes. I was not getting any error or warning while running the code so I assumed that there was no error
Thanks for the Information

@jakebailey
Copy link
Member

This issue has been fixed in version 2020.8.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202081-13-august-2020

@forestGoroli
Copy link

forestGoroli commented Oct 7, 2020

Thank you very much.
The same problem occurs in version 2020.9.8.
I confirmed that no error occurs when only the f-string is used. However, the same error message is displayed when the f-string and raw-string are combined, and a backslash is placed before the braces, as shown in the following example.

x = 'filename'
windows_path = rf'aaa\{x}'

I often use this style of writing to specify a file path in the Windows environment.
If my syntax is not correct in some way, I am very sorry for the time spent on this comment.

@erictraut
Copy link
Contributor

Thanks for reporting. You are correct that pylance was not handling backslashes correctly within a raw f-string. This will be addressed in the next release.

@forestGoroli
Copy link

@erictraut
I appreciate your prompt reply.
That fix would be very helpful for me.

@jakebailey jakebailey reopened this Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

4 participants