FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-104572: Improve error messages for invalid constructs in PEP 695 contexts by JelleZijlstra · Pull Request #104573 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
62 changes: 62 additions & 0 deletions Lib/test/test_syntax.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve syntax error message for invalid constructs in :pep:`695` contexts
and in annotations when ``from __future__ import annotations`` is active.
8 changes: 4 additions & 4 deletions Python/symtable.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@
"assignment expression cannot be used in a comprehension iterable expression"

#define ANNOTATION_NOT_ALLOWED \
"'%s' can not be used within an annotation"
"%s cannot be used within an annotation"

#define TYPEVAR_BOUND_NOT_ALLOWED \
"'%s' can not be used within a TypeVar bound"
"%s cannot be used within a TypeVar bound"

#define TYPEALIAS_NOT_ALLOWED \
"'%s' can not be used within a type alias"
"%s cannot be used within a type alias"

#define TYPEPARAM_NOT_ALLOWED \
"'%s' can not be used within the definition of a generic"
"%s cannot be used within the definition of a generic"

#define DUPLICATE_TYPE_PARAM \
"duplicate type parameter '%U'"
Expand Down

Back | FazBrowse Home | New Git URL