Skip to content

report error for unsolved type variables in function calls#1749

Open
KotlinIsland wants to merge 1 commit into
mainfrom
unsolved-type-var
Open

report error for unsolved type variables in function calls#1749
KotlinIsland wants to merge 1 commit into
mainfrom
unsolved-type-var

Conversation

@KotlinIsland
Copy link
Copy Markdown
Collaborator

@KotlinIsland KotlinIsland commented Mar 5, 2026

@KotlinIsland KotlinIsland requested a review from DetachHead March 5, 2026 03:08
Comment thread packages/pyright-internal/src/analyzer/typeEvaluator.ts Outdated
Comment thread packages/pyright-internal/src/analyzer/typeEvaluator.ts
Comment thread packages/pyright-internal/src/analyzer/typeEvaluator.ts Outdated
@KotlinIsland KotlinIsland requested a review from DetachHead March 5, 2026 03:21
@KotlinIsland KotlinIsland force-pushed the unsolved-type-var branch 3 times, most recently from 6ff7dcd to c5fcd37 Compare March 5, 2026 04:29
@github-actions

This comment has been minimized.

@KotlinIsland KotlinIsland force-pushed the unsolved-type-var branch 3 times, most recently from 868276b to 09ecbcc Compare March 5, 2026 06:16
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the example from that issue still doesn't report an error:

a = []

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the error message is pretty confusing in this case:

Type variable "T" has no solution; consider providing it explicitly

maybe for list/set/dict/etc. literals it should give an example of how to fix it, eg:

Type variable "T" has no solution; consider providing it explicitly (eg. list[int]())

maybe that can be a diagnostic addendum

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I like suggesting
a = list[int]()
when
a: list[int] = []
would have better performance.

Comment thread packages/pyright-internal/src/tests/samples/typeVarUnsolved1.py
Comment thread packages/pyright-internal/src/tests/samples/typeVarUnsolved1.py Outdated
Comment thread packages/pyright-internal/src/tests/samples/typeVarUnsolved1.py Outdated
@github-actions

This comment has been minimized.

@KotlinIsland
Copy link
Copy Markdown
Collaborator Author

@DetachHead ci failed for some flake i think, wanna review?

@DetachHead
Copy link
Copy Markdown
Owner

that can happen if you push the same commit multiple times, it tries to publish a canary version that already exists

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the primer has raised some false positives, or at least scenarios that need investigating

@github-actions

This comment was marked as duplicate.

}
},
{
"code": "reportUnsolvedTypeVar",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like this name.

"Solving" a type variable is a perspective of the type-checker implementer, that the type-checker user shouldn't need to think about.

The user doesn't need to think about "solving" things, or "solutions".

This kind of seems like something for the family of reportUnknown... rules.
reportUnknownTypeVar?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while the term is possibly confusing since type checkers seem to have different words for it (pyright uses the word "specialize" but idk if that term is unique to pyright), i don't consider the actual resolving of a type var to be an implementation detail. the user should be able to clearly tell when using a function or class with a generic whether that generic was able to be inferred or not, regardless of what word is used to describe that process.

i agree reportUnknownTypeVar sounds like a better name, and is more consistent with other similar rules

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.

report an error when a type variable cannot be resolved

3 participants