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

*args type checking #20

Closed
max-sixty opened this issue Jul 1, 2020 · 8 comments
Closed

*args type checking #20

max-sixty opened this issue Jul 1, 2020 · 8 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@max-sixty
Copy link

max-sixty commented Jul 1, 2020

Environment data

  • Language Server version: 2020.6.1
  • OS and version: MacOS
  • Python version (& distribution if applicable, e.g. Anaconda): Python3.7

Expected behaviour

@jakebailey suggested I open a new issue based on #15 (comment)

From that issue:

The dims issue is a third thing (separate again), as it's saying that you can't unpack Hashable into a *args parameter, which is true from a type checking point of view. If you believe that message to be wrong, I'd file a separate issue for that one as well, especially if you have the type checking mode set to "off".

I'm not sure this is correct. mypy & the pep seems fairly explicit that *args: Hashable should expect each of the args to Hashable, not args itself to be Hashable:
https://www.python.org/dev/peps/pep-0484/#arbitrary-argument-lists-and-default-argument-values

Copying the requested screenshot from the attached issue for convenience
image

Let me know if logs etc would be helpful.

Thank you!

@jakebailey
Copy link
Member

jakebailey commented Jul 1, 2020

Yes, dims should have type Tuple[Hashable] or Iterable[Hashable] (or similar, I can't recall the exact one used for variadic args as I'm typing this).

I'll likely clone this to check for myself, as this codebase seems to be very annotated (yay!), but if you remove that if block entirely, does the issue go away?

@max-sixty
Copy link
Author

I'm not sure that's the case, though. Here's a screenshot of the link above:

image

Removing the if block does fix it. Why is that? Presumably entering the if block means that dims must be a tuple, which is iterable?

@erictraut
Copy link
Contributor

This is definitely a bug in pyright/pylance. I'm debugging it now. In some code path (not yet determined) it's not treating the type of args as a Tuple. In other code paths it does. Stay tuned for a fix. And thanks for reporting the problem.

@jakebailey
Copy link
Member

jakebailey commented Jul 1, 2020

When I said "should have type Tuple[Hashable]", I meant the actual type of the dims variable within the function scope, not that you should annotate it as such. *dims: Hashable is a valid annotation.

@max-sixty
Copy link
Author

When I said "should have type Tuple[Hashable]", I meant the actual type of the dims variable within the function scope, not that you should annotate it as such. *dims: Hashable is a valid annotation.

Great, I see, thanks

@erictraut
Copy link
Contributor

I found and fixed the bug and added some additional unit tests. It will be fixed in the next release. Thanks again for the bug report.

@erictraut erictraut added the bug Something isn't working label Jul 1, 2020
@max-sixty
Copy link
Author

Thank you! Feel free to close!

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jul 2, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202070-9-july-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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