-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty collection's subtype evaluates to Unknown
when in tuple passed to Iterable with TypeVar parameter
#4244
Comments
b1 = bar(["A", "B", ()])
b2 = bar(["A", "B", []]) # missing error (bug)
b3 = bar(["A", "B", {}]) # missing error (bug)
b4 = bar(("A", "B", ()))
b5 = bar(("A", "B", [])) # error reportUnknownArgumentType
b6 = bar(("A", "B", {})) # error reportUnknownArgumentType I think pyright is correct to report an "unknown argument type" for the expressions assigned to However, I agree that there is an inconsistency here. The expressions Calls to The expression This will be addressed in the next release. |
…st or dict literal is included in a list expression with an "expected type" (i.e. bidirectional type inference is being attempted). This addresses #4244.
Not the bug I thought but glad to have found an inconsistency nonetheless. How would you recommend dealing with b2, b3, b5, b6? Is a cast necessary here? |
That depends on what type you expect |
|
This is addressed in pyright 1.1.282, which I just published. It will also be included in a future release of pylance. |
Describe the bug
An empty set or list inside a tuple used as a function parameter typed as
Iterable[_T]
(where_T
is aTypeVar
) will result inreportUnknownArgumentType
. This does not happen inside of lists. And does not happen if the empty collection is a tuple (likely because zero-length tuples are their own type). It also only happens withTypeVar
.To Reproduce
Expected behavior
No error (empty set infered as
dict[Any, Any]
and empty list aslist[Any]
), like all the other callsScreenshots or Code
VS Code extension or command-line
Pylance (v2022.11.30) and pyright (1.1.281), strict settings
The text was updated successfully, but these errors were encountered: