[Python-ideas] Why operators are useful
Antoine Pitrou
solipsis at pitrou.net
Tue Mar 19 09:00:16 EDT 2019
On Tue, 19 Mar 2019 10:49:41 +1300
Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Rémi Lapeyre wrote:
>
> > You can make "inferences from the way things are used". But the
> > comparison with maths stops here, you don’t make such inferences because your
> > object must be well defined before you start using it.
>
> In maths texts it's very common to see things like 'Let y = f(x)...'
> where it's been made clear beforehand (either explicitly or implicitly)
> what type f returns.
It's made clear because, when f was defined, it's explicitly spelled
out what are the source and destination domains (not sure that's the
right terminology). That's part of how you define a function in maths.
There's no such thing in Python, unless you enforce typing hints and/or
comprehensive docstrings.
> No, you don't, because most lines in most programs allow types to
> be inferred. The reason that things like MyPy are possible and
> useful is that Python programs in practice are usually well-typed.
You are being idealistic here. MyPy relies on typing hints being
available, and sufficiently precise.
Regards
Antoine.
More information about the Python-ideas
mailing list