Describe the bug
tm1py/TM1py/Objects/Process.py:24: DeprecationWarning: Flags not at the start of the expression '#\\*\\*\\*\\*Begin: Gene' (truncated)
Triggered by https://github.com/cubewise-code/tm1py/blob/master/TM1py/Objects/Process.py#L23
To Reproduce
pytest Tests/Application.py
Expected behavior
We should address the deprecation warning
Version
master branch
Additional context
Came up while looking at the tests for the application service.
Googling Flags not at the start of the expression suggests that it might be as simple as changing:
pattern = r"#\*\*\*\*Begin: Generated Statements(?s)(.*)#\*\*\*\*End: Generated Statements\*\*\*\*"
To:
python
pattern = r"(?s)#\*\*\*\*Begin: Generated Statements(.*)#\*\*\*\*End: Generated Statements\*\*\*\*"
I can see that regex is trying match to the auto generated block but not sure what the (?s) is trying to do. Maybe someone with a better understanding of regular expressions can help?
(?s) is the DOTALL flag in REGEX
It is useful when the pattern you are searching for may span across multiple lines.
Basically it can match all characters including line breaks.
Cool, thanks @rkvinoth. Can the (?s) be safely moved to beginning of the line then? If I've understood correctly, it shouldn't make a difference when trying to match the generated statement block. What do you think ?
#****Begin: Generated Statements***
#****End: Generated Statements****
#****Begin: Generated Statements*** and before #****End: Generated Statements****Lets go with the new approach:
pattern = r"(?s)#\*\*\*\*Begin: Generated Statements(.*)#\*\*\*\*End: Generated Statements\*\*\*\*"
Thanks @rkvinoth
Note I just realised I didn't copy and paste the code properly, have adjusted my comment now. That is, the original statement has the ?s but halfway through the string.
For clarity, the line I'm talking about is here:
I'll do ad hoc testing to make sure it does what it's supposed to.
Cheers
Alex
I did notice the code link you had posted initially.
The REGEX flag should be placed at the start of the expression..
Since we haven't, it is throwing the error.
Cool, thanks. I'll raise a PR, just didn't want to break anything just to suppress a warning I'm seeing on 3.8.
Cheers
Alex