Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"IndexError: no such group" with python 3.13.0rc2 #61

Closed
Prinz23 opened this issue Sep 8, 2024 · 3 comments
Closed

"IndexError: no such group" with python 3.13.0rc2 #61

Prinz23 opened this issue Sep 8, 2024 · 3 comments
Assignees
Labels

Comments

@Prinz23
Copy link

Prinz23 commented Sep 8, 2024

The following code results in the new python 3.13.0rc2 in an error, it works fine in all previous major python versions.

#set $match = re.search(r'(.*)\s(\(\w+\))$', 'test (add)', re.I | re.M)
$match.group(2)

results in error:

IndexError: no such group

@phdru phdru self-assigned this Sep 9, 2024
@phdru phdru added the bug label Sep 9, 2024
@phdru
Copy link
Member

phdru commented Sep 9, 2024

This is a problem in NameMapper, the central component of Cheetah. When it interprets $match.group(2) it first tries match['group'] and if got TypeError exception it continues with attribute access getattr(match, 'group'). Unfortunately MatchObject implements both attribute and index access, and match['group'] raises IndexError instead of TypeError because it's possible to do match[2] instead of match.group(2). Recently Python 3.13 started to catch more exceptions and that's where NameMapper fails. I'll think how to work around the problem.

Meanwhile you can change your template(s) to use match[2], that works; NameMapper doesn't map index access to attribute access, match[2] always means exactly that.

@phdru
Copy link
Member

phdru commented Sep 9, 2024

You can now install fixed CT3 from this commit:

pip install -U --compile git+https://github.com/CheetahTemplate3/cheetah3.git@d73945eaf635f9c9b14da945eddc9a8227eda85c

@Prinz23
Copy link
Author

Prinz23 commented Sep 9, 2024

After deleting the cached existing old whl, this fixed the issue for me.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants