SyntaxWarnings Raised During Build Process with Python 3.12

Issue #2760 new
Thiago Assumpcao created an issue

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 (10)

  1. Steven R. Brandt

    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 with

    submitpattern   = '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.

  2. Roland Haas

    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?

  3. Roland Haas

    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 a 1.

    Do you know where exactly it decides to interpret strings read from a file and do escape sequence processing on them?

  4. Steven R. Brandt

    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.

  5. Steven R. Brandt

    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?

  6. Roland Haas

    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).

  7. Log in to comment