SyntaxWarnings Raised During Build Process with Python 3.12
When executing the ./simfactory/bin/sim build
command with Python 3.12, I encountered several warnings related to invalid escape sequences. The warnings are as follows:
<string>:1: SyntaxWarning: invalid escape sequence '\d'
<string>:1: SyntaxWarning: invalid escape sequence '\('
Comments (12)
-
-
Steve says to look at lib/simlib.py line 1108.
-
The main problem seems to be the ini parser in 3.12. It complains about things like this:
submitpattern = 'Submitted batch job (\d+)'
The problem is that a
\d
is invalid inside a quoted string. To fix it, replace it withsubmitpattern = 'Submitted batch job (\\d+)'
or
submitpattern = Submitted batch job (\d+)
Both seem to work.
There are also some problems with a few strings inside simfactory that need to be r-strings.
-
Ouch, this is caused by strings in machine files? That will be much more of a problem than anticipated. For the ini parser: I would think it should not interpret the strings as anything, just strings. Is there a way to make it treat the input as raw strings.
Actually: since the ini file parser is home grown, this can be changed, can it?
-
-
Please review.
-
The Python changes look ok, but I would rather not have to duplicate all
\
and whatever else Python may consider special in the ini files. The strings are stated to be regular expressions in the docs and\\d
is not the PCRE that matches a1
.Do you know where exactly it decides to interpret strings read from a file and do escape sequence processing on them?
-
It seems that the ini file reader is the thing complaining. The strings still are regular expressions, but if a regular expression is in a quoted string it should be understood with quoted string escape rules. If you prefer, we could remove the quote marks and convert
\\d
to\d
. -
In particular, the problem comes about when this is called:
vv = eval(self.OriginalValue)
This means that we could also cure it by putting an r in front of the quotes, e.g.
submitpattern = r'Submitted batch job (\d+)'
Is this preferrable?
-
The version reached after discussing in the pull request that uses a regular expression to parse ini file input is reviewed positively. Please clean up the commit history and make sure that each commit is one logical change and its commit message is prefixed by the simfactory component being changed (
git log
may provide inspiration for the prefixes). -
- changed status to resolved
PR 69 is merged.
-
Applied as git hash 54f87bd3 "Merged in fix-python-syntax-warnings (pull request
#69)" of simfactory2 - Log in to comment
Could you provide a reproducer?