wickman / pystachio

type-checked dictionary templating library for python
MIT License
91 stars 22 forks source link

Fixup invalid escapes #52

Closed jmcrawford45 closed 1 year ago

jmcrawford45 commented 2 years ago

Regular expressions use the backslash character ('\') to indicate special forms or to allow special characters to be used without invoking their special meaning. This collides with Python’s usage of the same character for the same purpose in string literals; for example, to match a literal backslash, one might have to write '\\' as the pattern string, because the regular expression must be \, and each backslash must be expressed as \ inside a regular Python string literal. Also, please note that any invalid escape sequences in Python’s usage of the backslash in string literals now generate a DeprecationWarning and in the future this will become a SyntaxError. This behaviour will happen even if it is a valid escape sequence for a regular expression.

The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with 'r'. So r"\n" is a two-character string containing '\' and 'n', while "\n" is a one-character string containing a newline. Usually patterns will be expressed in Python code using this raw string notation.

jmcrawford45 commented 2 years ago
 find . -iname '*.py'  | xargs -P 4 -I{} /opt/ee/python/3.10/bin/python3 -Walways -m py_compile {}

git checkout master
Switched to branch 'master'
Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
 find . -iname '*.py'  | xargs -P 4 -I{} /opt/ee/python/3.10/bin/python3 -Walways -m py_compile {}

./pystachio/naming.py:90: DeprecationWarning: invalid escape sequence '\w'
  RE = re.compile('^[\w\-\./]+$')
./pystachio/naming.py:96: DeprecationWarning: invalid escape sequence '\d'
  RE = re.compile('^[^\d\W]\w*$')
shatil commented 1 year ago

Are you both the same Jared, @jcrawford13 and @jmcrawford45? Also, @wickman can we please land this two-line change?

jmcrawford45 commented 1 year ago

Yes @jmcrawford45 is my personal and @jcrawford13 is my old work GitHub. Btw there may not have been time for handoff of the project so I'm not sure that there's anyone left with repo admin access and the motivation to improve / maintain pystachio.