Segmentation fault when accesing a dict class attribute that is empty
- Dominant language
- Python
- Stars
- 16.8k
- Forks
- 603
- Avg merge
- 4d 23h
- Merged PRs (30d)
- 6
Description
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
Contributor guide
Assessment
This issue has not been assessed yet.