syntax difference

Chris Angelico rosuav at gmail.com
Mon Jun 18 14:18:06 EDT 2018


On Tue, Jun 19, 2018 at 4:09 AM, Jim Lee <jlee54 at gmail.com> wrote:
>
>
> On 06/18/2018 10:46 AM, Chris Angelico wrote:
>>
>> On Tue, Jun 19, 2018 at 3:34 AM, Jim Lee <jlee54 at gmail.com> wrote:
>>>
>>>
>>> On 06/18/2018 07:03 AM, Steven D'Aprano wrote:
>>>>
>>>> As a human programmer, you surely perform your own ad hoc type checking
>>>> when you write and debug code.
>>>
>>> Of course.  And, I use linting tools and other forms of static type
>>> checking.  What I don't like is adding the *syntax* for static type
>>> checking
>>> to the (dynamically typed) language proper, particularly when the
>>> implementations of said language do nothing but ignore it.
>>
>> So you have annotations for type information. Tell me: why should
>> these annotations be introduced with a hash and ended with a newline?
>> What is it about type annotations that requires that they be delimited
>> in this way?
>
> Uhhh....because that's mostly the definition of a comment?  Duh!

Yes, that's the definition of a comment. What is it about type
annotations that requires them to be comments? Please explain.

>> What about assertions? Are they comments too? Should we have, for
>> instance:
>>
>> if x > 0:
>>      ...
>> elif x < 0:
>>      ...
>> else:
>>      #assert: x == 0
>>      ...
>>
>> or is it better to use an 'assert' statement? After all, they can
>> legitimately be ignored by the interpreter.
>>
>> ChrisA
>
>
> I'm noticing a pattern here.  Can we stick to the subject at hand?

Yes, but probably not the same pattern you are. What, fundamentally,
is the difference between type hints and assertions, such that - in
your view - one gets syntax and the other is just comments?

ChrisA



More information about the Python-list mailing list