diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2023-05-17 06:05:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-17 06:05:42 -0700 |
commit | 97db2f3e07bf7d56750e215e4f32653bf3867ef8 (patch) | |
tree | 937151e98c3f0e16603209e9e968098b429b8564 /Lib/test/test_syntax.py | |
parent | 0cb2fdc6217aa7c04b5c798cfd195c8d0f4af353 (diff) | |
download | cpython-97db2f3e07bf7d56750e215e4f32653bf3867ef8.tar.gz cpython-97db2f3e07bf7d56750e215e4f32653bf3867ef8.zip |
gh-104572: Improve error messages for invalid constructs in PEP 695 contexts (#104573)
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r-- | Lib/test/test_syntax.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index f959bbb4400..477879db2fd 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -1877,6 +1877,68 @@ Invalid bytes literals: ^^^^^^^^^^^ SyntaxError: bytes can only contain ASCII literal characters +Invalid expressions in type scopes: + + >>> type A[T: (x:=3)] = int + Traceback (most recent call last): + ... + SyntaxError: named expression cannot be used within a TypeVar bound + + >>> type A[T: (yield 3)] = int + Traceback (most recent call last): + ... + SyntaxError: yield expression cannot be used within a TypeVar bound + + >>> type A[T: (await 3)] = int + Traceback (most recent call last): + ... + SyntaxError: await expression cannot be used within a TypeVar bound + + >>> type A[T: (yield from [])] = int + Traceback (most recent call last): + ... + SyntaxError: yield expression cannot be used within a TypeVar bound + + >>> type A = (x := 3) + Traceback (most recent call last): + ... + SyntaxError: named expression cannot be used within a type alias + + >>> type A = (yield 3) + Traceback (most recent call last): + ... + SyntaxError: yield expression cannot be used within a type alias + + >>> type A = (await 3) + Traceback (most recent call last): + ... + SyntaxError: await expression cannot be used within a type alias + + >>> type A = (yield from []) + Traceback (most recent call last): + ... + SyntaxError: yield expression cannot be used within a type alias + + >>> class A[T]((x := 3)): ... + Traceback (most recent call last): + ... + SyntaxError: named expression cannot be used within the definition of a generic + + >>> class A[T]((yield 3)): ... + Traceback (most recent call last): + ... + SyntaxError: yield expression cannot be used within the definition of a generic + + >>> class A[T]((await 3)): ... + Traceback (most recent call last): + ... + SyntaxError: await expression cannot be used within the definition of a generic + + >>> class A[T]((yield from [])): ... + Traceback (most recent call last): + ... + SyntaxError: yield expression cannot be used within the definition of a generic + """ import re |