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

pow NoReturn overload is used by Pyright and Pyre when argument types are not known #8566

Closed
debonte opened this issue Aug 19, 2022 · 2 comments · Fixed by #8568
Closed

pow NoReturn overload is used by Pyright and Pyre when argument types are not known #8566

debonte opened this issue Aug 19, 2022 · 2 comments · Fixed by #8568

Comments

@debonte
Copy link

debonte commented Aug 19, 2022

The first overload of pow currently looks like this:

@overload
def pow(base: int, exp: int, mod: Literal[0]) -> NoReturn: ...

When the argument types are not known, Pyright and Pyre use the first overload -- the NoReturn overload.

Here's an example from microsoft/pylance-release#3214:

def RSAcompute(message, exponent, pubkey):
    data = pow(message, exponent, pubkey)
    # The rest of the function is marked as unreachable
    # because Pyright/Pylance see pow's return type as NoReturn
    toto = 42
    return data

res = RSAcompute(12, 34, 56)
print("Similarly this line is considered unreachable")

@AlexWaygood, it looks like you added the NoReturn overload here. Does it actually help users? I'm wondering if it could be removed, or at least moved down in the overload ordering so Pyright and Pyre would behave better in this situation.

@JelleZijlstra
Copy link
Member

I think we should remove it. Returning NoReturn isn't a good fit for cases where the code throws an error the user probably isn't expecting, because it can easily lead to type checkers silently skipping the code. Ideally we'd be able to use something like TypingError from python/typing#1043. Until we have that, I think it's better to accept that we can't handle cases like this in the stub.

@AlexWaygood
Copy link
Member

Sure, let's get rid of it and add a TODO comment. Thanks for raising the issue @debonte.

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 a pull request may close this issue.

3 participants