Skip to content

Segmentation fault when accesing a dict class attribute that is empty #767

@variux

Description

@variux

I have the following code

class Row:
    __slots__ = ("_values", "_index")
    _values: Tuple[int, List[Any]]
    _index: Dict[str, int]

    def __init__(self, values: Tuple[int, List[Any]], colnames: List[str]):
        self._values = values
        self._index = {name: i for i, name in enumerate(colnames)}

values: List[Any] = List[Any]()
values.append(1)
values.append(2)
values.append(3)
row = Row((0, values), ["id", "name", "data"])
print(row._index)

if you try to un it, it works, but

This code

class Row:
    __slots__ = ("_values", "_index")
    _values: Tuple[int, List[Any]]
    _index: Dict[str, int]

    def __init__(self, values: Tuple[int, List[Any]], colnames: List[str]):
        self._values = values

values: List[Any] = List[Any]()
values.append(1)
values.append(2)
values.append(3)
row = Row((0, values), ["id", "name", "data"])
print(row._index)

when self._index is not filled, fails with Segmentation Fault, defining as _index: Dict[str, int] = Dict[str, int]() won't work neither

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions