-
Notifications
You must be signed in to change notification settings - Fork 11
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
Problems with parsing when an option includes escapes Python does not like #51
Comments
Can you provide me your This doesn't seem to reproduce for me on Ubuntu 22.04.4 LTS with Python 3.10.12 in the bash shell ~/tmp$ cat argparse_bug.R
library("argparse")
parser <- ArgumentParser(description='foo')
parser$add_argument('--bar', default = "[\\D]")
a <- parser$parse_args()
cat("bar: ", a$bar, "\n")
~/tmp$ Rscript argparse_bug.R
bar: [\D]
~/tmp$ Rscript argparse_bug.R --bar=[\\D]
bar: [\D] |
And presuming you use the vanilla
|
|
Looks like a new warning in Python 3.12:
|
Options seem to be:
|
* Character values are now passed as "raw" strings to Python + In particular this avoids triggering an error in Python 3.12 when creating a string with escapes not supported by Python e.g. `default = "\\D"` will continue to return a default value of `"\\D"` instead of triggering an error. + However, this also means that any Python accepted escape sequences will no longer be interpreted as an escape sequence. If relying on such behaviour you may need to instead use the appropriate R escape sequences or Unicode values instead of Python escape sequences: - E.g. `default = "\\t"` will now return a default value of `"\\t"` (a `t` preceded by an (escaped) backslash) instead of `"\t"` (a horizontal tab). - https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences - https://en.wikipedia.org/wiki/Basic_Latin_(Unicode_block) + Thanks Matthew Hall (@mdhall272) for bug report. closes #51
* Character values are now passed as "raw" strings to Python + In particular this avoids triggering an error in Python 3.12 when creating a string with escapes not supported by Python e.g. `default = "\\D"` will continue to return a default value of `"\\D"` instead of triggering an error. + However, this also means that any Python accepted escape sequences will no longer be interpreted as an escape sequence. If relying on such behaviour you may need to instead use the appropriate R escape sequences or Unicode values instead of Python escape sequences: - E.g. `default = "\\t"` will now return a default value of `"\\t"` (a `t` preceded by an (escaped) backslash) instead of `"\t"` (a horizontal tab). - https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences - https://en.wikipedia.org/wiki/Basic_Latin_(Unicode_block) + Thanks Matthew Hall (@mdhall272) for bug report. closes #51
* Character values are now passed as "raw" strings to Python + In particular this avoids triggering an error in Python 3.12 when creating a string with escapes not supported by Python e.g. `default = "\\D"` will continue to return a default value of `"\\D"` instead of triggering an error. + However, this also means that any Python accepted escape sequences will no longer be interpreted as an escape sequence. If relying on such behaviour you may need to instead use the appropriate R escape sequences or Unicode values instead of Python escape sequences: - E.g. `default = "\\t"` will now return a default value of `"\\t"` (a `t` preceded by an (escaped) backslash) instead of `"\t"` (a horizontal tab). - https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences - https://en.wikipedia.org/wiki/Basic_Latin_(Unicode_block) + Thanks Matthew Hall (@mdhall272) for bug report. closes #51
MWE:
The error is:
Error in if (grepl("^\\{|^\\[", output)) { : the condition has length > 1
The reason is apparently that python is adding a warning string
<stdin>:19: SyntaxWarning: invalid escape sequence '\\D'
tooutput
which causes an error at line 251 ofargparse.R
The text was updated successfully, but these errors were encountered: