-
Notifications
You must be signed in to change notification settings - Fork 171
Add support for dict
methods with Const
#2567
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
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
4d833da
Implement attributes for `Const dict`
kmr-srbh 3d65739
Remove duplicate changes
kmr-srbh 7cd71db
Improve checking for `Const` types
kmr-srbh 005fb72
Simplify type checking for `Const dict`.
kmr-srbh d7ea3bb
Merge branch 'main' into const-dict-methods
kmr-srbh 161bd8e
Add tests
kmr-srbh e75755b
Update test
kmr-srbh 1a068c8
Update fetching attribute name logic
kmr-srbh 68524a4
Update test references
kmr-srbh 6337279
Update fetching `dict_type`
kmr-srbh c422524
Formatting changes
kmr-srbh a047e71
Update test references
kmr-srbh 9917227
Update error test references
kmr-srbh 03d5998
Tests: Update test references
kmr-srbh 01748f7
Merge branch 'main' into const-dict-methods
kmr-srbh 22009cd
Tests: Add runtime tests and update test references
kmr-srbh 3b3a272
Merge branch 'main' into const-dict-methods
kmr-srbh 5b1dcd4
Merge branch 'main' into const-dict-methods
kmr-srbh 848f3e0
Merge branch 'main' into const-dict-methods
kmr-srbh e53a8bc
Merge branch 'main' into const-dict-methods
kmr-srbh 3b61a29
Merge branch 'main' into const-dict-methods
kmr-srbh 74dd5ce
Merge branch 'main' into const-dict-methods
kmr-srbh 737acb4
Remove checks on the absent `Const` node
kmr-srbh 4a2942f
Remove call to `get_contained_type()`
kmr-srbh 6f19980
Tests: Add tests and update references
kmr-srbh 5988ca2
Merge branch 'main' into const-dict-methods
kmr-srbh 634011c
Style changes
kmr-srbh 8579851
Tests: Update tests and add to CMakeLists
kmr-srbh 809fe8d
Delete tests/reference/asr-test_const_dict-151acad.json
kmr-srbh f0de6cf
Delete tests/reference/asr-test_const_dict-151acad.stdout
kmr-srbh 6c086e3
Delete tests/reference/asr-test_const_dict-59445d7.json
kmr-srbh 7e0a8c2
Delete tests/reference/asr-test_dict_const-69479e2.json
kmr-srbh e0c4d62
Delete tests/reference/asr-test_dict_const-69479e2.stderr
kmr-srbh 3307acf
Delete tests/reference/asr-test_dict_const-69479e2.stdout
kmr-srbh aa6c245
Delete tests/reference/runtime-test_dict_const-62054df.json
kmr-srbh cab3eea
Delete tests/reference/runtime-test_dict_const-62054df.stderr
kmr-srbh c740e70
Delete tests/reference/asr-test_const_dict-59445d7.stderr
kmr-srbh 9581a31
Tests: Update error references
kmr-srbh 78e4205
Undo formatting changes
kmr-srbh 891c001
Remove extra newline
kmr-srbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,24 @@ | ||
from lpython import i32, f64, Const | ||
|
||
CONST_DICTIONARY_INTEGR: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} | ||
|
||
print(CONST_DICTIONARY_INTEGR.get("a")) | ||
assert CONST_DICTIONARY_INTEGR.get("a") == 1 | ||
|
||
print(CONST_DICTIONARY_INTEGR.keys()) | ||
assert len(CONST_DICTIONARY_INTEGR.keys()) == 3 | ||
|
||
print(CONST_DICTIONARY_INTEGR.values()) | ||
assert len(CONST_DICTIONARY_INTEGR.values()) == 3 | ||
|
||
CONST_DICTIONARY_FLOAT: Const[dict[str, f64]] = {"a": 1.0, "b": 2.0, "c": 3.0} | ||
|
||
print(CONST_DICTIONARY_FLOAT.get("a")) | ||
assert CONST_DICTIONARY_FLOAT.get("a") == 1.0 | ||
|
||
print(CONST_DICTIONARY_FLOAT.keys()) | ||
assert len(CONST_DICTIONARY_FLOAT.keys()) == 3 | ||
|
||
print(CONST_DICTIONARY_FLOAT.values()) | ||
assert len(CONST_DICTIONARY_FLOAT.values()) == 3 | ||
|
This file contains hidden or 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 hidden or 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,9 @@ | ||
from lpython import i32, f64, dict, Const | ||
|
||
|
||
def test_const_dict(): | ||
CONST_DICTIONARY: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} | ||
print(CONST_DICTIONARY.pop("a")) | ||
|
||
|
||
test_const_dict() |
This file contains hidden or 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,13 @@ | ||
{ | ||
"basename": "asr-test_const_dict-59445d7", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_const_dict.py", | ||
"infile_hash": "51130e98c759eb3cdbd50848e59879e4689d241c7a8674aa06a5b3c7", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_const_dict-59445d7.stderr", | ||
"stderr_hash": "1d3729d80a7895dd01baaf0905c6cc9ebadd7f7ce623f4ae5970e2b8", | ||
"returncode": 2 | ||
} |
This file contains hidden or 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 @@ | ||
semantic error: cannot pop elements from a const dict | ||
--> tests/errors/test_const_dict.py:6:11 | ||
| | ||
6 | print(CONST_DICTIONARY.pop("a")) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.