[Python-ideas] PEP 484 (Type Hints) -- first draft round
Cem Karan
cfkaran2 at gmail.com
Sun Jan 18 23:24:51 CET 2015
On Jan 18, 2015, at 9:16 AM, Chris Angelico <rosuav at gmail.com> wrote:
> On Mon, Jan 19, 2015 at 12:37 AM, Cem Karan <cfkaran2 at gmail.com> wrote:
>> There may be other uses of annotations that programmers haven't yet thought of, simply because they don't know that annotations exist. Locking out those uses would suck.
>
> I see a lot of vague "but what if there's something else", and not a
> lot of concrete "here's a use of annotations that would be locked
> out". Does anyone actually have another use case that would be
> seriously harmed by this kind of conflict? Remember, you can simply
> not use type hints for the function(s) that use other annotations; the
> conflict is only if you're trying to use both on the same function.
def foo(a: {Type(int), Doc("some doc")}, b):
pass
vs.
def foo(a, b):
"""
:param a: some doc
:type a: int
"""
pass
With annotations, the documentation lives with the argument. If typing rules all, then you might accidentally have the following:
def foo(a: int, b):
"""
:param a: some doc
:type a: str <- Whoops! Type conflict!
"""
pass
Or the ugly but workable:
def foo(a: int, b):
"""
:param a: some doc
"""
pass
I'm arguing that with annotations we can put a lot more information in about a given function argument/return value than just typing. Typing and documentation are two things that I can think of off the top of my head. I can't think of others off of the top of my head, but I suspect that is due to my lack of imagination and not the lack of potential.
Thanks,
Cem Karan
More information about the Python-ideas
mailing list