Tm1py: Minor - Adjust regex in Objects/Process.py to avoid deprecation

Created on 8 Aug 2020  路  6Comments  路  Source: cubewise-code/tm1py

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?

bug

All 6 comments

(?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 ?

  1. With the new REGEX we are saying that the below statement could span across multiple lines in the new REGEX.
#****Begin: Generated Statements***
#****End: Generated Statements****
  1. With the old REGEX we were saying that there could be one or more line breaks after #****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:

https://github.com/cubewise-code/tm1py/blob/7478943c8fbdcfbdcc701b40cc7dd3b6f9e1d0b3/TM1py/Objects/Process.py#L23

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yyzz1010 picture yyzz1010  路  3Comments

VY109 picture VY109  路  4Comments

cubewise-gng picture cubewise-gng  路  3Comments

hermie64 picture hermie64  路  3Comments

user1493 picture user1493  路  3Comments