-
Notifications
You must be signed in to change notification settings - Fork 250
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
Added draft chapter to typing spec for named tuples #1614
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, a few editorial issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: should Unpack[]
be mentioned here?
@sobolevn, you asked about |
@erictraut And since One more related thing: https://peps.python.org/pep-0646/ does not mention |
@sobolevn, "unpacking a tuple" is different from using the special form For example, this is allowed: from typing import Unpack
def func[*Ts](x: tuple[int, Unpack[tuple[str, ...]]], *args: Unpack[Ts]) -> tuple[Unpack[Ts]]: ... This is equivalent to: def func[*Ts](x: tuple[int, *tuple[str, ...]], *args: *Ts) -> tuple[*Ts]: ... The Named tuples, like regular tuples, can be unpacked using the unpack operator or through a destructuring assignment. NT = namedtuple("NT", "x y z")
my_tuple = (1, 2, 3)
my_named_tuple = NT(1, 2, 3)
t1 = [*my_tuple]
t2 = [*my_named_tuple]
a, b, c, = my_tuple
x, y, z = my_named_tuple |
@erictraut yes, this is exactly why I am asking.
You can unpack Is it worth mentioning in the docs that you cannot do that, what do you think? |
As I said, "unpacking a tuple" isn't the same as using the |
… to better match Python documentation.
No description provided.