rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
582 stars 32 forks source link

SyntaxError: invalid syntax #95

Closed pierre-chataigner closed 1 year ago

pierre-chataigner commented 1 year ago

Hi,

I've encountered this error. djhtml with python 3.9.5 I believe it might be solved by replacing if changed := _verify_changed(source, result): by if (changed := _verify_changed(source, result)): (with parenthesis) in accordance with PEP 572 : Relative precedence of :=

JaapJoris commented 1 year ago

The walrus operator currently appears in the following places:

djhtml/__main__.py
88:        if changed := _verify_changed(source, result):

djhtml/lines.py
51:        if text := self.text.strip():
68:            if value := getattr(self, attr):

djhtml/modes.py
217:        if tag := re.match(self.OPENING_TAG, raw_token):
246:        if regex := self.AMBIGUOUS_BLOCK_TAGS.get(name):
290:            if match := re.match(r"([\w\-\.:]+)(\s*)", src):
317:            if tagname := re.search(r"\w+", raw_token):

djhtml/tokens.py
34:                if value := getattr(self, attr):

Are you saying that all of these usages are incorrect? Then why do the unittests pass with Python 3.8, 3.9, 3.10 and 3.11?

pierre-chataigner commented 1 year ago

Problem came from my side, my bad.