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

Type error in Pylance #3348

Closed
denisrosset opened this issue May 18, 2022 · 8 comments · Fixed by #3349
Closed

Type error in Pylance #3348

denisrosset opened this issue May 18, 2022 · 8 comments · Fixed by #3349
Labels
interop how to play nicely with other packages

Comments

@denisrosset
Copy link

denisrosset commented May 18, 2022

This is with Pylance language server 2022.5.1 (pyright e0e07d31), Python 3.10 and hypothesis 6.46.5

Edit: the analysis mode is strict:

    "python.analysis.typeCheckingMode": "strict",

The following snippet:

from typing import Tuple

import hypothesis.strategies as st

def my_hyp() -> st.SearchStrategy[Tuple[int, int]]:
    return st.tuples(st.integers(0, 10), st.integers(0, 10))

fails to typecheck with:

Type of "tuples" is partially unknown
  Type of "tuples" is "Overload[() -> SearchStrategy[Tuple[()]], (a1: SearchStrategy[Ex@tuples]) -> SearchStrategy[Tuple[Ex@tuples]], (a1: SearchStrategy[Ex@tuples], a2: SearchStrategy[T@tuples]) -> SearchStrategy[Tuple[Ex@tuples, T@tuples]], (a1: SearchStrategy[Ex@tuples], a2: SearchStrategy[T@tuples], a3: SearchStrategy[T3@tuples]) -> SearchStrategy[Tuple[Ex@tuples, T@tuples, T3@tuples]], (a1: SearchStrategy[Ex@tuples], a2: SearchStrategy[T@tuples], a3: SearchStrategy[T3@tuples], a4: SearchStrategy[T4@tuples]) -> SearchStrategy[Tuple[Ex@tuples, T@tuples, T3@tuples, T4@tuples]], (a1: SearchStrategy[Ex@tuples], a2: SearchStrategy[T@tuples], a3: SearchStrategy[T3@tuples], a4: SearchStrategy[T4@tuples], a5: SearchStrategy[T5@tuples]) -> SearchStrategy[Tuple[Ex@tuples, T@tuples, T3@tuples, T4@tuples, T5@tuples]], (*args: SearchStrategy[Any]) -> SearchStrategy[Tuple[Unknown, ...]], (*args: Unknown) -> TupleStrategy]"

I'd be happy to push this myself to the pylance issues if I'm advised to!

@Zac-HD
Copy link
Member

Zac-HD commented May 18, 2022

Ah, it might want us to prefix the pos-only argnames with an underscore? Or it might be some other issue that we can solve locally. Thanks for the report!

@Zac-HD Zac-HD added the interop how to play nicely with other packages label May 18, 2022
@denisrosset
Copy link
Author

denisrosset commented May 18, 2022

If I had to guess, it's because of the Tuple without arguments in the "real" declaration. I've got the same error message in numpy.

I think this should be pushed to Pylance/Pyright:
https://github.com/microsoft/pylance-release/issues

I've edited the issue to precise that the analysis mode is strict.

@Zac-HD
Copy link
Member

Zac-HD commented May 18, 2022

Ah, if you've got the same error from Numpy then it probably does make sense to treat it as a pyright issue, since I'm pretty sure it's pyright rather than pylance. Do you want to open that upstream, and tag me?

@rsokl
Copy link
Contributor

rsokl commented May 18, 2022

I don't think that there is a problem with pyright here. This is fixed by updating both lines 110 and 116 in collections.py to:

def tuples(*args: SearchStrategy[Any]) -> SearchStrategy[Tuple[Any, ...]]:  # noqa: F811

@denisrosset
Copy link
Author

@rsokl Cool! so Any is the magic escape valve for such issues?

@rsokl
Copy link
Contributor

rsokl commented May 18, 2022

Specifying Tuple is indeed a partially unknown annotation. pyright-strict wants you to tell it "I explicitly mean that it is a tuple of arbitrary length and contents", which is spelled by Tuple[Any, ...].

Similarly, e.g., Dict would be partially unknown until you specify Dict[Any, Any]

And, for some reason, pyright-strict expects that the actual implementation (line 116) to also include annotations, even though this seems to be redundant with the lowest overload. I haven't taken the time to see if mypy wants the same.

@Zac-HD I can try to fix this sometime today. Would you also like me to make the overloads use pos-only args (a1 -> __a1)?

@Zac-HD
Copy link
Member

Zac-HD commented May 18, 2022

Thanks! Yeah, let's also use pos-only args - they are in fact positional-only, so.

@rsokl
Copy link
Contributor

rsokl commented May 18, 2022

For the record, the same issue occurs in one_of. I am doing a general tune up in #3349

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interop how to play nicely with other packages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants