This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JelleZijlstra
Recipients AlexWaygood, JelleZijlstra, gvanrossum, kj, tfish2
Date 2022-04-05.20:52:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1649191963.06.0.307787776087.issue47234@roundup.psfhosted.org>
In-reply-to
Content
Thanks for your report, but I would appreciate a more concise explanation. Let me try to rephrase the problem.

Given this function:

def mean(x: list[float]) -> float:
    return sum(x) / len(x)

We want to provide a guarantee that if x is a nonempty list containing only floats, the function returns successfully and returns a float.

But the type system currently doesn't give this guarantee, because PEP 484 specifies that ints are compatible with floats, and `mean([0.0, 1.25, 10**1000, 0.0])` will throw OverflowError.

---

We generally discuss issues with the general type system over at https://github.com/python/typing/issues, but here are a few thoughts:

- The type system doesn't generally try to cover exceptions. Your function could also raise MemoryError, or KeyboardInterrupt, and the type system can't tell you.
- The concrete proposal here would be to make int no longer implicitly compatible with float. That might be nice, but at this point it would be a big break in backwards compatibility, so I'm not sure we can do it.
History
Date User Action Args
2022-04-05 20:52:43JelleZijlstrasetrecipients: + JelleZijlstra, gvanrossum, kj, AlexWaygood, tfish2
2022-04-05 20:52:43JelleZijlstrasetmessageid: <1649191963.06.0.307787776087.issue47234@roundup.psfhosted.org>
2022-04-05 20:52:43JelleZijlstralinkissue47234 messages
2022-04-05 20:52:42JelleZijlstracreate