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

Strictness option to use precise returns types for certain stdlib functions #6214

Closed
JukkaL opened this issue Jan 17, 2019 · 4 comments
Closed

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 17, 2019

The return type of int.__pow__ is Any, since the precise type depends on the value of the right operand. Maybe we should have a strictness option that makes the return type float instead. This probably shouldn't be enabled by default, since it can generate false positives. We could use the same thing for pow() and perhaps some other commonly used stdlib functions -- and maybe even for JSON return values from json once we have recursive types.

See #6210 for context.

@ilevkivskyi
Copy link
Member

The question is were the alternative (more strict) types would be stored? If also somewhere in typeshed, then we might need to have some syntax for this (or use the Annotated[...] proposal, which is kind of almost universal syntax):

from typing import Annotated
from mypy_extensions import MypyStrict

class int:
    def __pow__(self, other: float) -> Annotated[Any, MypyStrict[float]]: ...

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 18, 2019

I'm not sure what's the best way to implement the strict types. If only a handful of functions are affected, we could use the plugin system. If there are a large number of them, the Annoted[...] idea seems worth considering.

@ilevkivskyi
Copy link
Member

ilevkivskyi commented Jan 18, 2019

Mabe we should collect some preliminary list of possible candidates? @JelleZijlstra @srittau do you have any candidates in typeshed where a return type is Any to avoid false positives?

@JelleZijlstra
Copy link
Member

python/typing#1096 is a more recent iteration of this idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants