syntax difference

Chris Angelico rosuav at gmail.com
Tue Jun 19 06:21:10 EDT 2018


On Tue, Jun 19, 2018 at 8:12 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Mon, 18 Jun 2018 11:34:40 -0700, Jim Lee wrote:
>
>> On 06/18/2018 11:18 AM, Chris Angelico wrote:
>>> What, fundamentally, is the difference between type hints and
>>> assertions, such that - in
>>> your view - one gets syntax and the other is just comments?
>> Type hints are just that - hints.  They have no syntactic meaning to the
>> parser, and do not affect the execution path in any way. Therefore, they
>> are effectively and actually comments.  The way they have been
>> implemented, though, causes noise to be interspersed with live code and,
>> as others have said, are difficult to remove or ignore.
>
> So let me get this straight...
>
> Using annotations is evil, because it intersperses noise with live code:
>
> def function(argument: int,
>              flag: bool,
>              sequence: list) -> str:
>     ...
>
>
> But using comments is great, because it doesn't:
>
> def function(argument,  # type=int,
>              flag,  # type=bool,
>              sequence, # type=list):  # type=str
>     ...
>
>
> Okay, I'm glad we cleared that up.
>

Isn't it nice how comments, being terminated exclusively by
end-of-line, allow the introduction of subtle bugs? Let's see how many
people spot the (presumably deliberate) bug in Steve's code here.

ChrisA



More information about the Python-list mailing list