-
Notifications
You must be signed in to change notification settings - Fork 135
Closed
astral-sh/ruff
#21044Labels
diagnosticsRelated to reporting of diagnostics.Related to reporting of diagnostics.help wantedContributions especially welcomeContributions especially welcome
Description
The invalid-argument diagnostic doesn't contain enough information for me to fix the diagnostic if the union gets truncated:
def arg(a: list[str] | str | dict[str, str] | list[int]| set[str] | int):
assert len(a) == 1, (
"ensure_config should not modify the original config"
)Argument to function `len` is incorrect: Expected `Sized`, found `list[str] | str | dict[str, str] | ... omitted 3 union elements` (invalid-argument-type) [Ln 2, Col 16]
The problematic element is int but it doesn't appear in the list.
We should improve the invalid-argument diagnostic to explicitly call out the argument that isn't compatible. Not only does that fix the issue with truncated union types, it also removes the need for users to second-guess which union element is the problematic one.
https://play.ty.dev/0ef049ec-72e9-4700-9fca-bfc1a45f965d
Related discussion astral-sh/ruff#20730 (comment)
sharkdp
Metadata
Metadata
Assignees
Labels
diagnosticsRelated to reporting of diagnostics.Related to reporting of diagnostics.help wantedContributions especially welcomeContributions especially welcome