-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
pylint doesn't understand returns from functions using match case #5288
Comments
Maybe a bit simpler code to reproduce: def foo() -> tuple[int, int]:
match 1:
case int(a):
return a, 5
case None:
return 0, 0
x, y = foo() Adding a |
I can reproduce with @Sasszem example. |
We need astroid to understand returns from match statements: >>> import astroid
>>> code = """
... 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, " "
...
... z = check_user_can_add_friend('uu') #@
... """
>>> n = astroid.extract_node(code)
>>> n.targets[0].inferred()
[<Const.NoneType l.None at 0x1105ff090>] |
Closing as I don't have immediate plans to work on this. |
Whoops, wrong tab. I definitely have plans to work on this. I just put up a PR on astroid: pylint-dev/astroid#2042 |
Bug description
Pylint displays the following error code:
Error message: 'Attempting to unpack a non-sequence'
Details:
When the following code snippet is used:
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
Configuration
No response
Command used
Pylint output
Expected behavior
Pylance should not show any error for this line as it can be correctly unpacked.
Pylint version
OS / Environment
Windows 10 Enterprise (10.0.18363 Build 18363)
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: