This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #420 from icon-project/IS-1021-dict-db-iteration-c…
…auses-infinite-loop IS-1021: DictDB iteration causes infinite loop
- Loading branch information
Showing
5 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/integrate_test/samples/sample_scores/sample_dict_db/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": "0.0.1", | ||
"main_file": "sample_dict_db", | ||
"main_score": "IterableDictDB" | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/integrate_test/samples/sample_scores/sample_dict_db/sample_dict_db.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Example | ||
Problem with DictDB : cannot iterate | ||
https://forum.icon.community/t/problem-with-dictdb-cannot-iterate/484 | ||
""" | ||
|
||
from iconservice import * | ||
TAG = 'IterableDictDB' | ||
|
||
|
||
class IterableDictDB(IconScoreBase): | ||
""" IterableDictDB SCORE Base implementation """ | ||
|
||
# ================================================ | ||
# Initialization | ||
# ================================================ | ||
def __init__(self, db: IconScoreDatabase) -> None: | ||
super().__init__(db) | ||
self._dict = DictDB('DICT', db, value_type=int) | ||
|
||
def on_install(self) -> None: | ||
super().on_install() | ||
|
||
def on_update(self) -> None: | ||
super().on_update() | ||
|
||
@external | ||
def create_item(self, key: str, value: int) -> None: | ||
self._dict[key] = value | ||
|
||
@external(readonly=True) | ||
def get_items(self) -> list: | ||
items = [] | ||
for item in self._dict: | ||
items.append(item) | ||
return items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters