Skip to content

nonlocal bug to crash #1758

@youknowone

Description

@youknowone

Feature

code

def test_var_annot_refleak(self):
    # complex case: custom locals plus custom __annotations__
    # this was causing refleak
    cns = CNS()
    nonloc_ns = {'__annotations__': cns}
    class CNS2:
        def __init__(self):
            self._dct = {'__annotations__': cns}
        def __setitem__(self, item, value):
            nonlocal nonloc_ns
            self._dct[item] = value
            nonloc_ns[item] = value
        def __getitem__(self, item):
            return self._dct[item]
    exec('X: str', {}, CNS2())
    self.assertEqual(nonloc_ns['__annotations__']['x'], str)

expected result: silent exit without error

actual result:

SyntaxError: no binding for nonlocal 'nonloc_ns' found at line 0 column 0

Python Documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-compatA discrepancy between RustPython and CPython

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions