mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-104572: Improve error messages for invalid constructs in PEP 695 contexts (#104573)
This commit is contained in:
parent
0cb2fdc621
commit
97db2f3e07
3 changed files with 68 additions and 4 deletions
|
|
@ -1877,6 +1877,68 @@ def f(x: *b)
|
|||
^^^^^^^^^^^
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue