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

Attempting to unpack a non-sequence, raised when using a match method returning a tuple #2060

Closed
wangoland opened this issue Nov 10, 2021 · 2 comments

Comments

@wangoland
Copy link

Environment data

  • Language Server version: Pylance language server 2021.11.0 (pyright fb86eac6)
  • OS and version: Windows 10 Enterprise (10.0.18363 Build 18363)
  • Python version (& distribution if applicable, e.g. Anaconda): 3.10

Expected behaviour

Pylance should not show any error for this line as it can be correctly unpacked.

Actual behaviour

The result returned from the function can be unpacked, however pylance incorrectly reports the error below indicating that it can't:
Error message: 'Attempting to unpack a non-sequence'
Details:

[{
	"resource": "/c:/[REDACTED]/main.py",
	"owner": "python",
	"code": "unpacking-non-sequence",
	"severity": 8,
	"message": "Attempting to unpack a non-sequence",
	"source": "pylint",
	"startLineNumber": 124,
	"startColumn": 5,
	"endLineNumber": 124,
	"endColumn": 5
}]

Logs

[Info  - 08:12:06] Pylance language server 2021.11.0 (pyright fb86eac6) starting
[Info  - 08:12:06] Server root directory: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist
[Info  - 08:12:06] No pyproject.toml file found.
[Info  - 08:12:06] Setting pythonPath for service "<default>": "C:\Python310\python.exe"
[Warn  - 08:12:06] stubPath typings is not a valid directory.
[Info  - 08:12:07] Assuming Python version 3.10
[Info  - 08:12:07] Assuming Python platform Windows
[Info  - 08:12:07] Searching for source files
[Info  - 08:12:07] No source files found.
[Info  - 08:12:07] Background analysis(1) root directory: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist
[Info  - 08:12:07] Background analysis(1) started
[Info  - 08:16:59] No pyproject.toml file found.
[Info  - 08:16:59] Setting pythonPath for service "<default>": "C:\Python310\python.exe"
[Warn  - 08:16:59] stubPath typings is not a valid directory.
[Info  - 08:17:00] Assuming Python version 3.10
[Info  - 08:17:00] Assuming Python platform Windows
Search paths for <default>
  c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib
  typings
  c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stubs\...
  c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\bundled\stubs
  c:\Python310\DLLs
  c:\Python310\Lib
  c:\Python310
  c:\Python310\Lib\site-packages
[Info  - 08:17:00] Searching for source files
[Info  - 08:17:00] No source files found.
Background analysis message: setConfigOptions
Background analysis message: setImportResolver
Background analysis message: ensurePartialStubPackages
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: getSemanticTokens delta
[BG(1)] getSemanticTokens delta previousResultId:1636531927751 at c:\[REDACTED]\main.py ...
[BG(1)]   parsing: c:\[REDACTED]\main.py (53ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 10ms] (95ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\builtins.pyi (25ms)
[BG(1)]   binding: c:\[REDACTED]\main.py (9ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\typing.pyi [fs read 5ms] (33ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\typing.pyi (4ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi [fs read 7ms] (17ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi (2ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\types.pyi [fs read 5ms] (16ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\types.pyi (5ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\typing_extensions.pyi [fs read 6ms] (7ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\typing_extensions.pyi (1ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\abc.pyi [fs read 6ms] (7ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\abc.pyi (4ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\socket.pyi [fs read 7ms] (16ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\socket.pyi (2ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\time.pyi [fs read 5ms] (7ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\time.pyi (0ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\threading.pyi [fs read 5ms] (8ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\threading.pyi (3ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\socketserver.pyi [fs read 5ms] (8ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\socketserver.pyi (1ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\sqlite3\__init__.pyi [fs read 6ms] (7ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\sqlite3\__init__.pyi ...
[BG(1)]     parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\sqlite3\dbapi2.pyi [fs read 6ms] (9ms)
[BG(1)]     binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\sqlite3\dbapi2.pyi (4ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\sqlite3\__init__.pyi (14ms)
[BG(1)]   parsing: c:\Python310\Lib\site-packages\bcrypt\__init__.py [fs read 6ms] (17ms)
[BG(1)]   binding: c:\Python310\Lib\site-packages\bcrypt\__init__.py (1ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\os\__init__.pyi [fs read 6ms] (19ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\os\__init__.pyi (4ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\_socket.pyi [fs read 7ms] (12ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\_socket.pyi (6ms)
[BG(1)]   parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\enum.pyi [fs read 6ms] (7ms)
[BG(1)]   binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\enum.pyi (0ms)
[BG(1)] getSemanticTokens delta previousResultId:1636531927751 at c:\[REDACTED]\main.py (714ms)
Background analysis message: analyze
[BG(1)] analyzing: c:\[REDACTED]\main.py ...
[BG(1)]   checking: c:\[REDACTED]\main.py (45ms)
[BG(1)] analyzing: c:\[REDACTED]\main.py (45ms)
Background analysis message: resumeAnalysis
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
[FG] parsing: c:\[REDACTED]\main.py (65ms)
[FG] parsing: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 3ms] (76ms)
[FG] binding: c:\[REDACTED]\.vscode\extensions\ms-python.vscode-pylance-2021.11.0\dist\typeshed-fallback\stdlib\builtins.pyi (24ms)
[FG] binding: c:\[REDACTED]\main.py (6ms)
Background analysis message: getDiagnosticsForRange

Code Snippet / Additional information

Note: In the examples above '[REDACTED]' is used to hide any non-required information.

def check_user_can_add_friend(username):
    # Get subscription level
    subscription_level = user_get_subscription_level(username)
    number_friend_requests = user_count_friend_requests(username)
    number_friends = number_friend_requests + user_count_friends(username)

    match subscription_level:
        case "BASIC":
            if number_friends < 5:
                return True, " "
            else:
                return False, "'" + username + "' can only have a maximum of 5 friends"
        case "GOLD":
            if number_friends < 20:
                return True, " "
            else:
                return False, "'" + username + "' can only have a maximum of 20 friends"
        case _:
            return True, " "

If the above match statement is changed to an if and elseif statement then the error reported by pylance for un-packing will go away

@erictraut
Copy link
Contributor

This error message is coming from pylint, not from pylance. Please report the issue to the maintainers of pylint.

@wangoland
Copy link
Author

Raised with PyLint: pylint-dev/pylint#5288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants