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

Missing support for unparenthesized expression list as match subject #1044

Closed
pewscorner opened this issue Mar 13, 2021 · 5 comments
Closed
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@pewscorner
Copy link

Environment data

  • Language Server version: 2021.3.1
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.0a6

Expected behaviour

According to the syntax section of PEP 634 the new match statement takes a subject_expr which may be an unparenthesized list of comma-separated star_named_expressions, and this works fine in Python 3.10.0a6, so Pylance should not complain about it. I realize that Python 3.10.0 hasn't been released yet, but since Pylance seems to already handle most match syntax correctly, I thought I'd mention this deficit.

Actual behaviour

Pylance covers the code in squiggly red lines if the subject_expr contains commas and is not parenthesized.

Logs

User belongs to experiment group 'pythonaa'
User belongs to experiment group 'pythonSendEntireLineToREPL'
User belongs to experiment group 'pythonNotDisplayLinterPrompt'
User belongs to experiment group 'pythonTensorboardExperiment'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'DeprecatePythonPath - experiment'
> conda --version
> pyenv root
> python3.7 c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3.6 c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3.7 c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3 c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -2 c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> conda info --json
> python c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
Starting Pylance language server.
Python interpreter path: D:\Python\Python310\python.exe
Error 2021-03-13 11:44:57: Detection of Python Interpreter for Command python3 and args  failed as file  does not exist
Error 2021-03-13 11:44:59: Failed to get interpreter information for 'D:\Python\Python24\python.exe' [Error: Command failed: "D:\\Python\Python24\python.exe" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\interpreterInfo.py"
Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py", line 9, in ?
    import runpy
ImportError: No module named runpy

	at ChildProcess.exithandler (child_process.js:312:12)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1021:16)
	at Socket.<anonymous> (internal/child_process.js:443:11)
	at Socket.emit (events.js:315:20)
	at Pipe.<anonymous> (net.js:674:12)] {
  killed: false,
  code: 1,
  signal: null,
  cmd: '"D:\\\\Python\\Python24\\python.exe" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\pyvsc-run-isolated.py" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\interpreterInfo.py"'
}
Error 2021-03-13 11:44:59: Failed to get interpreter information for 'C:\Users\User\AppData\Local\Microsoft\WindowsApps\python3.exe' [Error: Command failed: "C:\\Users\User\AppData\Local\Microsoft\WindowsApps\python3.exe" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\interpreterInfo.py"
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

	at ChildProcess.exithandler (child_process.js:312:12)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1021:16)
	at Socket.<anonymous> (internal/child_process.js:443:11)
	at Socket.emit (events.js:315:20)
	at Pipe.<anonymous> (net.js:674:12)] {
  killed: false,
  code: 9009,
  signal: null,
  cmd: '"C:\\\\Users\\User\\AppData\\Local\\Microsoft\\WindowsApps\\python3.exe" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\pyvsc-run-isolated.py" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\interpreterInfo.py"'
}
Error 2021-03-13 11:44:59: Failed to get interpreter information for 'C:\Users\User\AppData\Local\Microsoft\WindowsApps\python.exe' [Error: Command failed: "C:\\Users\User\AppData\Local\Microsoft\WindowsApps\python.exe" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\interpreterInfo.py"
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

	at ChildProcess.exithandler (child_process.js:312:12)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1021:16)
	at Socket.<anonymous> (internal/child_process.js:443:11)
	at Socket.emit (events.js:315:20)
	at Pipe.<anonymous> (net.js:674:12)] {
  killed: false,
  code: 9009,
  signal: null,
  cmd: '"C:\\\\Users\\User\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\pyvsc-run-isolated.py" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\interpreterInfo.py"'
}
Error 2021-03-13 11:44:59: Failed to get interpreter information for 'C:\Users\User\AppData\Local\Microsoft\WindowsApps\python.exe' [Error: Command failed: "C:\\Users\User\AppData\Local\Microsoft\WindowsApps\python.exe" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\interpreterInfo.py"
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

	at ChildProcess.exithandler (child_process.js:312:12)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1021:16)
	at Socket.<anonymous> (internal/child_process.js:443:11)
	at Socket.emit (events.js:315:20)
	at Pipe.<anonymous> (net.js:674:12)] {
  killed: false,
  code: 9009,
  signal: null,
  cmd: '"C:\\\\Users\\User\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\pyvsc-run-isolated.py" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\interpreterInfo.py"'
}
Error 2021-03-13 11:44:59: Failed to get interpreter information for 'D:\Python\Python26\python.exe' [Error: Command failed: "D:\\Python\Python26\python.exe" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\interpreterInfo.py"
Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py", line 30, in <module>
    runpy.run_path(module, run_name="__main__")
AttributeError: 'module' object has no attribute 'run_path'

	at ChildProcess.exithandler (child_process.js:312:12)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1021:16)
	at Socket.<anonymous> (internal/child_process.js:443:11)
	at Socket.emit (events.js:315:20)
	at Pipe.<anonymous> (net.js:674:12)] {
  killed: false,
  code: 1,
  signal: null,
  cmd: '"D:\\\\Python\\Python26\\python.exe" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\pyvsc-run-isolated.py" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\interpreterInfo.py"'
}
Error 2021-03-13 11:44:59: Failed to get interpreter information for 'D:\Python\Python25\python.exe' [Error: Command failed: "D:\\Python\Python25\python.exe" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\interpreterInfo.py"
Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py", line 30, in <module>
    runpy.run_path(module, run_name="__main__")
AttributeError: 'module' object has no attribute 'run_path'

	at ChildProcess.exithandler (child_process.js:312:12)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1021:16)
	at Socket.<anonymous> (internal/child_process.js:443:11)
	at Socket.emit (events.js:315:20)
	at Pipe.<anonymous> (net.js:674:12)] {
  killed: false,
  code: 1,
  signal: null,
  cmd: '"D:\\\\Python\\Python25\\python.exe" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\pyvsc-run-isolated.py" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\interpreterInfo.py"'
}
Error 2021-03-13 11:44:59: Failed to get interpreter information for 'C:\Users\User\AppData\Local\Microsoft\WindowsApps\python3.exe' [Error: Command failed: "C:\\Users\User\AppData\Local\Microsoft\WindowsApps\python3.exe" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\pyvsc-run-isolated.py" "c:\Users\User\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\interpreterInfo.py"
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

	at ChildProcess.exithandler (child_process.js:312:12)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1021:16)
	at Socket.<anonymous> (internal/child_process.js:443:11)
	at Socket.emit (events.js:315:20)
	at Pipe.<anonymous> (net.js:674:12)] {
  killed: false,
  code: 9009,
  signal: null,
  cmd: '"C:\\\\Users\\User\\AppData\\Local\\Microsoft\\WindowsApps\\python3.exe" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\pyvsc-run-isolated.py" "c:\\Users\\User\\.vscode\\extensions\\ms-python.python-2021.2.636928669\\pythonFiles\\interpreterInfo.py"'
}
> conda --version
> D:\Python\Python310\python.exe -c "
import unittest
loader = unittest.TestLoader()
suites = loader.discover(".", pattern="*unittest.py")
print("start") #Don't remove this line
for suite in suites._tests:
    for cls in suite._tests:
        try:
            for m in cls._tests:
                print(m.id())
        except:
            pass"
cwd: d:\Documents\Python
> D:\Python\Python310\python.exe -c "
import unittest
loader = unittest.TestLoader()
suites = loader.discover(".", pattern="*unittest.py")
print("start") #Don't remove this line
for suite in suites._tests:
    for cls in suite._tests:
        try:
            for m in cls._tests:
                print(m.id())
        except:
            pass"
cwd: d:\Documents\Python

Code Snippet / Additional information

Without parentheses (bad)

match 1, 2:
    case x, y:
        print(x, y)

image

With parentheses (OK)

match (1, 2):
    case x, y:
        print(x, y)

image

@pewscorner
Copy link
Author

pewscorner commented Mar 13, 2021

Note that even the syntax highlighting here on Github doesn't recognize the match keyword in the code snippet with the unparenthesized subject. Or maybe it is highlighting functions rather than keywords.

@erictraut
Copy link
Contributor

Thanks for pointing that out. I missed that part in PEP 634. I've modified the parser in pylance to support this. This will be fixed in the next release of pylance.

The new pattern-matching feature introduces a significant addition to the Python grammar, so it's going to take a while for tools and libraries to add support. The library that github uses for syntax highlighting is one of many that will need to be updated.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Mar 13, 2021
@pewscorner
Copy link
Author

Sounds great, thanks!

No, I wasn't really expecting any tools to support the new feature yet, but for a moment I thought github was recognizing the match keyword in one of my snippets, so that's why I mentioned it. Now I realize that it was simply being colored as a function name due to the parentheses - not as a keyword.

@jakebailey
Copy link
Member

This issue has been fixed in version 2021.3.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202132-17-march-2021

@pewscorner
Copy link
Author

It works! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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

3 participants