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

Why is the product of Real numbers Any? #11340

Closed
Kakadus opened this issue Jan 29, 2024 · 4 comments
Closed

Why is the product of Real numbers Any? #11340

Kakadus opened this issue Jan 29, 2024 · 4 comments

Comments

@Kakadus
Copy link

Kakadus commented Jan 29, 2024

Consider the following code:

from numbers import Real

a: Real
b: Real
reveal_type(a * b)  # Any
reveal_type(a + b)  # Any
reveal_type(a - b)  # Any
reveal_type(a / b)  # Any

reveals Any during typechecking. Why is this the case? Even if b is typed as int or float, the result is still Any

From a mathematical perspective, this does not seem to make much sense.

I'm using latest mypy on python 3.11

@srittau
Copy link
Collaborator

srittau commented Jan 29, 2024

Looking at the numbers module, while many arguments and return types are explicitly annotated using Any, I think most of those are actually unannotated. Many Anys were added in #4401, possibly to remove warnings about partially/unannotated methods. Maybe @erictraut remembers details.

@JelleZijlstra
Copy link
Member

Note that the numbers module in general doesn't play well with type checking; see python/mypy#3186 for much background on why.

I don't see a reason why we can't annotate the return types of method like Real.__add__, though.

@erictraut
Copy link
Contributor

@srittau, I don't remember the details of that PR. I think I was on a mission at that time to get all of the stdlib stubs to be "complete" with regard to return type annotations.

@srittau
Copy link
Collaborator

srittau commented Jan 30, 2024

I've removed the Any annotations. Now at least we clearly mark the stubs as unannotated. Any PR to improve the situation welcome! I'm going to close the issue though, since we don't keep issues for unannotated stubs open. Thanks, for reporting this, @Kakadus!

@srittau srittau closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2024
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

No branches or pull requests

4 participants