Skip to content

fix: use "constraints and a bound" in TypeVar error message#21126

Open
nuglifeleoji wants to merge 1 commit intopython:masterfrom
nuglifeleoji:fix/typevar-constraints-error-message
Open

fix: use "constraints and a bound" in TypeVar error message#21126
nuglifeleoji wants to merge 1 commit intopython:masterfrom
nuglifeleoji:fix/typevar-constraints-error-message

Conversation

@nuglifeleoji
Copy link
Copy Markdown
Contributor

Fixes #20973.

PEP 484 uses constraints for the positional type arguments of TypeVar
(e.g. TypeVar("T", int, str)) and bound for the bound= keyword.
The existing error message used neither term correctly:

error: TypeVar cannot have both values and an upper bound

Updated to the standard PEP 484 terminology:

error: TypeVar cannot have both constraints and a bound

Changed mypy/semanal.py and the matching test fixture in
test-data/unit/semanal-errors.test.

Made with Cursor

PEP 484 uses "constraints" for the positional arguments of TypeVar
(e.g. TypeVar("T", int, str)) and "bound" for the keyword argument.
The existing message "cannot have both values and an upper bound" used
neither term correctly.  Updated to:

  TypeVar cannot have both constraints and a bound

Closes python#20973

Made-with: Cursor
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

process_typevar_parameters(), its relates and error message should be corrected

1 participant