Skip to content

Conversation

@markshannon
Copy link
Member

@markshannon markshannon commented Feb 10, 2022

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I'm curious to see the results.

(I'm gonna be really surprised if anybody is out here unpacking zero-length iterables, though.)

@sweeneyde
Copy link
Member

(I'm gonna be really surprised if anybody is out here unpacking zero-length iterables, though.)

To my surprise, this works:

() = [] 
@brandtbucher
Copy link
Member

brandtbucher commented Feb 11, 2022

To my surprise, this works:

() = [] 

...for some definition of "works". The whole thing gets peepholed out. ;)

I think maybe once long ago I used something like this to "assert" that an iterator I used was completely exhausted (the idea being that it would raise a TypeError if not):

it = iter(something) # ...do some stuff... [] = it # Fails if there are any remaining items.

I thought it was pretty clever at the time. :)

@markshannon
Copy link
Member Author

UNPACK_SEQUENCE 0 does occur. In this:

def f(x): match x: case T(): pass
 1 0 RESUME 0 2 2 LOAD_FAST 0 (x) 3 4 LOAD_GLOBAL 0 (T) 6 LOAD_CONST 1 (()) 8 MATCH_CLASS 0 10 COPY 1 12 POP_JUMP_IF_NONE 10 (to 20) 14 UNPACK_SEQUENCE 0 4 16 LOAD_CONST 0 (None) 18 RETURN_VALUE 3 >> 20 POP_TOP 22 LOAD_CONST 0 (None) 24 RETURN_VALUE 
@markshannon markshannon merged commit 15ee555 into python:main Feb 14, 2022
@markshannon markshannon deleted the unpack-sequence-len-stats branch February 14, 2022 10:01
@brandtbucher
Copy link
Member

UNPACK_SEQUENCE 0 does occur.

Interesting. That's a common case that's worth improving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants