-
Notifications
You must be signed in to change notification settings - Fork 164
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
Added str.replace() #2587
Added str.replace() #2587
Conversation
I don't get any errors upon running |
It's the C test that fails, you can reproduce it using the following command: $ cd integration_tests
$ ./run_tests.py -b c |
Please mark this PR ready for review once it is ready! |
Fixed. Thank you @Thirumalai-Shaktivel . |
@Shaikh-Ubaid @Thirumalai-Shaktivel Please let me know if this is good to be merged. |
I think the implementation fails for the following example: % cat examples/expr2.py
from lpython import i32
def main0():
x: str
x = "abc"
print(x.replace("", ","))
assert x.replace("", ",") == ",a,b,c,"
main0()
% python examples/expr2.py
,a,b,c,
% lpython examples/expr2.py
,a,b,c
AssertionError |
Fixed. Thanks. |
@@ -0,0 +1,13 @@ | |||
(KEYWORD "def") 0:2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did this file got commited? I think it should not be present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not committed this, as this is in stdout, so I believe it is due to updated references.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not committed this, as this is in stdout, so I believe it is due to updated references.
Can you trying doing:
rm -rf tests/reference/* (then press 'y' if asked for confirmation)
./run_tests.py -u
git add tests
git commit -m "TEST: Update reference tests"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is supposed to happen? I did this, but nothing got committed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon rerunning these commands, I noticed there are no net changes. All the deleted files reappear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you follow the exact steps in #2587 (comment)?
The output shared in #2587 (comment) seems strange and does not look like exact steps were used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon rerunning these commands, I noticed there are no net changes. All the deleted files reappear.
Can you rebase over the latest main? I think that might help remove the stray file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this has been done from your side. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the file is now removed. We had to rebase over latest main, rebuild the project and then follow the steps in #2587 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks. I'm deleting the output now, as it is too long.
assert a.replace("b","k",1) == "zzaaakracadabra" | ||
assert a.replace("b","k",2) == "zzaaakracadakra" | ||
assert a.replace("zza","yo",2) == "yoaabracadabra" | ||
assert x.replace("", ",") == ",a,b,c," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We next need support for compile-time strings in replace. For example,
% cat examples/expr2.py
def main0():
print("abc".replace("", ","))
main0()
% python examples/expr2.py
,a,b,c,
% lpython examples/expr2.py
semantic error: 'str' object has no attribute 'replace'
--> examples/expr2.py:2:11
|
2 | print("abc".replace("", ","))
| ^^^^^^^^^^^^^^^^^^^^^^
Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.
I think this can be tackled in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Please let me know how to implement this. Also, is this done for all other functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Search for "upper"
in python_ast_to_asr.cpp
and you will find the place(s) for compile-time implementation.
I would suggest supporting it in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thanks for working on this! Great work! I appreciate it.
Towards: #2356
In this PR, I have implemented
str.replace()
completely. Relevant tests have also been added.Parameters: