From 697312cae5a886a533198e2c2457436c9eefb526 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 6 Jan 2025 14:09:39 +0800 Subject: [PATCH] fix impl of pep695 --- src/compiler/compiler.c | 6 ++++-- tests/96_pep695_py312.py | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index cdae54c2..b6aee04c 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -2269,8 +2269,10 @@ static Error* consume_pep695_py312(Compiler* self) { // https://peps.python.org/pep-0695/ Error* err; if(match(TK_LBRACKET)) { - consume(TK_ID); - if(match(TK_COLON)) { check(consume_type_hints(self)); } + do { + consume(TK_ID); + if(match(TK_COLON)) check(consume_type_hints(self)); + } while(match(TK_COMMA)); consume(TK_RBRACKET); } return NULL; diff --git a/tests/96_pep695_py312.py b/tests/96_pep695_py312.py index 3d456e79..7832fc20 100644 --- a/tests/96_pep695_py312.py +++ b/tests/96_pep695_py312.py @@ -15,3 +15,7 @@ assert res == 3 test = Test(1) assert test.get_value() == 1 + +# test multiple +class Test2[T: int, U]: pass +class Test3[T: int | str, U: float, R: list]: pass