Skip to content
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

Better error message for overloading functions that return union type #2020

Closed
binh-vu opened this issue Nov 1, 2021 · 4 comments
Closed
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@binh-vu
Copy link

binh-vu commented Nov 1, 2021

Networkx, a popular library for working with graph, uses lots of overloading. One example is iterating through edges in the graph. It can returns an iterator of tuples of 3 or 4 items (if keys argument is true). For example:

g = nx.MultiDiGraph()
...
# pylance complains that: Tuple size mismatch: expected 3 but received 4
for uid, vid, edge_data in g.edges(data=True):
    pass

# pylance compalins that: Tuple size mismatch: expected 4 but received 3
for uid, vid, eid, edge_data in g.edges(data=True, keys=True):
    pass

The error message is quite confusing because at first it told me to use a tuple of 4, but then when I use tuple of 4, it told me to use a tuple of 3. It would be better if the error message could mention the union type so the developers know that they need to do type narrowing or use type guard.

@github-actions github-actions bot added the triage label Nov 1, 2021
@erictraut
Copy link
Contributor

Thanks for reporting this. I agree the current behavior is confusing.

@erictraut
Copy link
Contributor

This will be addressed in the next release of pylance.

@erictraut erictraut added enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Nov 2, 2021
@erictraut
Copy link
Contributor

The new diagnostic message is a multi-line message with additional details. This is consistent with other diagnostic messages provided by pylance.

Screen Shot 2021-11-02 at 1 21 10 AM

@heejaechang
Copy link
Contributor

fixed in 2021.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants