On Thu, Apr 25, 2019 at 6:42 PM Peter O'Connor <peter.ed.ocon...@gmail.com>
wrote:

> Despite the general beauty of Python, I find myself constantly violating
> the "don't repeat yourself" maxim when trying to write clear, fully
> documented code.  Take the following example:
>

You do know that OPTIONAL type annotations are optional, right.  There's no
requirement to repeat yourself if you don't want to.

But in general, comments or docstrings can do something very different from
just annotate one variable at a time.  If I want to describe the
interaction of `a` and `b`, that simply cannot fit in an annotation/comment
per parameter.  Of if one argument switches the relevance or meaning of
another, etc.


> - Argument/return documentation can be made inline with a new "?"
> operator.  Documentation becomes a first class citizen.
>

We already have a first-class citizen in annotations, this seems like extra
burden for little reason.


>     def func_1(
>             a: int = 1 ? 'Something about param a',
>             b: float = 2.5 ? 'Something else about param b',
>             ) -> float ? 'Something about return value of func_1':
>         """ Something about func_1 """
>         return a*b
>

Why not just this in existing Python:

    def func_1(
            a: int = 1 # 'Something about param a',
            b: float = 2.5 # 'Something else about param b',
            ) -> float:
        """Something about func_1

        a and b interact in this interesting way.
        a should be in range 0 < a < 125
        floor(b) should be a prime number

        Something about return value of func_1
        returns a multiplication
        """
        return a*b


-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to