Closed
Description
Bug report
Bug description:
We disallow certain expressions (e.g., yield
) in type parameters bounds, constraints, and defaults. But the error message always says it's a bound:
>>> def f[T=(yield)](): pass
File "<python-input-0>", line 1
SyntaxError: yield expression cannot be used within a TypeVar bound
>>> def f[T: (int, (yield))](): pass
File "<python-input-2>", line 1
SyntaxError: yield expression cannot be used within a TypeVar bound
We could either add some machinery in the symbol table so it knows whether we're in a bound, constraints, or default, or just change the error message to something like "within a TypeVar bound, constraints, or default".
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response