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

Lambda keyword-only argument not updating co_freevars #57552

Closed
JoshuaLandau mannequin opened this issue Nov 4, 2011 · 8 comments
Closed

Lambda keyword-only argument not updating co_freevars #57552

JoshuaLandau mannequin opened this issue Nov 4, 2011 · 8 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@JoshuaLandau
Copy link
Mannequin

JoshuaLandau mannequin commented Nov 4, 2011

BPO 13343
Nosy @amauryfa, @mdickinson, @merwok
Files
  • issue13343.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2011-11-04.21:32:07.831>
    created_at = <Date 2011-11-04.19:37:32.067>
    labels = ['interpreter-core', 'type-crash']
    title = 'Lambda keyword-only argument not updating co_freevars'
    updated_at = <Date 2011-11-18.14:52:20.856>
    user = 'https://bugs.python.org/JoshuaLandau'

    bugs.python.org fields:

    activity = <Date 2011-11-18.14:52:20.856>
    actor = 'eric.araujo'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-11-04.21:32:07.831>
    closer = 'amaury.forgeotdarc'
    components = ['Interpreter Core']
    creation = <Date 2011-11-04.19:37:32.067>
    creator = 'Joshua.Landau'
    dependencies = []
    files = ['23612']
    hgrepos = []
    issue_num = 13343
    keywords = ['patch']
    message_count = 8.0
    messages = ['147026', '147031', '147033', '147037', '147043', '147044', '147046', '147877']
    nosy_count = 5.0
    nosy_names = ['amaury.forgeotdarc', 'mark.dickinson', 'eric.araujo', 'python-dev', 'Joshua.Landau']
    pr_nums = []
    priority = 'critical'
    resolution = 'fixed'
    stage = 'needs patch'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue13343'
    versions = ['Python 3.2', 'Python 3.3']

    @JoshuaLandau
    Copy link
    Mannequin Author

    JoshuaLandau mannequin commented Nov 4, 2011

    When setting defaults to keyword-only arguments in lambdas which are inside non-global scopes, cPython doesn't push the name to it's closure's co_freevars.

    EXAMPLE:
    global_variable = None
    (lambda: (lambda *, keyword_only=global_variable: None))()

    Because the inner lambda hasn't told the outer lambda to put global_variable in co_freevars, it fails to create the default to keyword_only. This only happens if the inner function is a lambda and you are setting a keyword_only variable.

    It does not cause a crash if global_variable is local to the outer lambda, as the opcode LOAD_FAST is still created properly (as opposed to LOAD_NAME).

    It does not crash if global_variable is used elsewhere in the outer function as co_freevars will be updated with it, allowing LOAD_NAME to retrieve it.

    I've never done a bug here before and I'm unsure what to say, so please be nice and correct me if I'm doing it wrong.

    @JoshuaLandau JoshuaLandau mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Nov 4, 2011
    @amauryfa
    Copy link
    Member

    amauryfa commented Nov 4, 2011

    Here is a patch, with a minimal test.

    @amauryfa
    Copy link
    Member

    amauryfa commented Nov 4, 2011

    same patch, without tabs.

    @mdickinson
    Copy link
    Member

    Patch looks good to me.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 4, 2011

    New changeset 1e0e821d2626 by Amaury Forgeot d'Arc in branch '3.2':
    Issue bpo-13343: Fix a SystemError when a lambda expression uses a global
    http://hg.python.org/cpython/rev/1e0e821d2626

    New changeset bddb455439d0 by Amaury Forgeot d'Arc in branch 'default':
    Issue bpo-13343: Fix a SystemError when a lambda expression uses a global
    http://hg.python.org/cpython/rev/bddb455439d0

    @amauryfa
    Copy link
    Member

    amauryfa commented Nov 4, 2011

    It was a bug in Python compiler, thanks for the report!

    @amauryfa amauryfa closed this as completed Nov 4, 2011
    @JoshuaLandau
    Copy link
    Mannequin Author

    JoshuaLandau mannequin commented Nov 4, 2011

    Glad to help :)
    It's made my day. I get to boast at school now!

    @merwok
    Copy link
    Member

    merwok commented Nov 18, 2011

    It's made my day. I get to boast at school now!
    You could do more of that if you got a patch committed! See http://docs.python.org/devguide and http://mail.python.org/mailman/listinfo/core-mentorship for more info if you’re interested.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants