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

bpo-46072: Include length in stats for UNPACK_SEQUENCE. #31254

Merged
merged 1 commit into from Feb 14, 2022

Conversation

Copy link
Member

@markshannon markshannon commented Feb 10, 2022

Copy link
Member

@brandtbucher brandtbucher left a comment

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

@sweeneyde sweeneyde commented Feb 11, 2022

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

To my surprise, this works:

() = []

@brandtbucher
Copy link

@brandtbucher 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
Author

@markshannon markshannon commented Feb 14, 2022

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
11 checks passed
@markshannon markshannon deleted the unpack-sequence-len-stats branch Feb 14, 2022
@brandtbucher
Copy link

@brandtbucher brandtbucher commented Feb 14, 2022

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants