Skip to content

Method call on imported definition differs inside of a list comprehension #127929

@DinoV

Description

@DinoV

Bug report

Bug description:

import re
[x for x in [] if re.match(".*", x)]

vs:

import re
re.match(".*", x)

When you disassemble these you'll see the inlined one will be doing a LOAD_ATTR 3 (match + NULL|self) while the one outside of the comprehension will be doing a PUSH_NULL/CALL which is to disable the method call optimization on things which are likely not methods.

These should both have the same byte code. There's no perceivable code execution difference other than performance though.

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions