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

Please allow doing one-liners such as `a: int, b: int = 1, 2` #664

guillaume-chevalier opened this issue Aug 6, 2019 · 3 comments


Copy link

commented Aug 6, 2019

By the way, if this is not the proper place to open the issue, could you please link to the good place or existing issue and close this one? Thx!


This comment has been minimized.

Copy link

commented Aug 6, 2019

That is intentionally disallowed because the priority of the comma is ambiguous.


This comment has been minimized.

Copy link

commented Aug 7, 2019

I wouldn't have expected the commas to cause ambiguity in the order things are parsed. Eliminating any possible ambiguity, this works:

    (a, b) = do_something(1, 2)
    (a), (b) = do_something(1, 2)
    ((a), (b)) = do_something(1, 2)

I'd love that this worked too, to avoid having to use many lines nor wrapping the function to define the return type:

    ((a: int), (b: int)) = do_something(1, 2)

If possible, I'd prefer doing this if the priority of the , is fine with the priority of the : :

    a: int, b: int = do_something(1, 2)

To the best of my understanding, I don't expect that a: int, b: int would be interpreted as a: (int, b: int) by the interpreter, but rather, I think it is (a: int), (b: int). If I'm wrong, then I understand that enabling people to do ((a: int), (b: int)) = do_something(1, 2) is not a priority because of the rarity of using such parentheses on the left hand side.

I'm also supposing more complicated types than int, and supposing that do_something's return type is unclear. This issue happened to me 2 to 4 times in the last weeks. I don't have anything more to add.


This comment has been minimized.

Copy link

commented Aug 7, 2019

As @JukkaL just mentioned in the other thread (and I totally agree with him) the recommended way is:

a: int
b: int
a, b = do_something(1, 2)

This question was already discussed in PEP 526, I don't think anything changed since that time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.