-
Notifications
You must be signed in to change notification settings - Fork 158
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
Fixes #2490: Adds unescaping \f
and the correct implementation of isspace()
string method.
#2551
Conversation
… all whitespace characters.
\f
and adds the correct implementation of the isspace()
string method.\f
and adds the correct implementation of the isspace()
string method.
\f
and adds the correct implementation of the isspace()
string method.\f
and the correct implementation of isspace()
string method.
What is the status of this PR? |
It is ready for review @Thirumalai-Shaktivel. |
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.
Also, add a test
@@ -974,16 +1103,18 @@ def _lpython_str_isupper(s: str) -> bool: | |||
return False | |||
return is_cased_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.
Remove all the formatting changes and you can submit a new PR for it.
# If none of the characters match, we have atleast one character which is not | ||
# a whitespace, so we return `False`. | ||
if ( | ||
ch_ord != 9 |
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.
Thanks for handling all the cases, but it doesn't seems to be more readable.
By readable what I meant is, I have to manually check what 9
is, and confirm that \t
is handled.
Was there any issue with previous changes?
Also, instead of this long condition check, why not keep the strings in list and have a single condition check?
x += "\f"; | ||
idx++; | ||
} | ||
else if (s[idx] == '\\' && s[idx + 1] == '\\') { |
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.
Please remove the formatting changes.
Please mark this PR ready for review once it is ready. |
Fix:
#2490 gave wrong output due to the incorrect handling of the escape sequence '\f'. Escaping the sequence was handled, but unescaping was missed. This led to the string
" \t\n\v\f\r"
being transformed to" \t\n\v\\f\r"
in the AST. Note the extra "\" after "v".Hence, the answer in #2490 was thus 'not actually' wrong as non-whitespace and lowercase characters did exist. Fixes #2490
Improvement
Though the error in the above case was due to incorrect string handling, the
isspace()
method was actually not implemented correctly. The definition of a 'whitespace' character is actually broad. The Python interpreter checks for all of them in it's implementation of the method. I incorporated checking for those characters.A huge shout-out to @advikkabra for the clever testing. 🎉
Note
The Black formatter has automatically formatted the Python file I worked on. Please note that only change I made was the implementation of the
isspace()
method.Last but not the least, I thoroughly enjoyed working on the issue. 😃