syntax difference
Bart
bc at freeuk.com
Mon Jun 18 06:33:19 EDT 2018
On 18/06/2018 01:10, Chris Angelico wrote:
> On Mon, Jun 18, 2018 at 9:30 AM, Rick Johnson
> <rantingrickjohnson at gmail.com> wrote:
>> On Sunday, June 17, 2018 at 2:07:40 PM UTC-5, Jim Lee wrote:
>>
>>> IMHO, trying to shoehorn static type checking on top of a dynamically
>>> typed language shows that the wrong language was chosen for the job.
>>
>> Exactly.
>>
>> I'm not against the idea of Python growing a new feature.
>> Features are great. My objection is concerned merely with
>> the "how" it is implemented, not the "why" it was
>> implemented.
>>
>> "Type-hint comments" would allow:
>>
>> (1) those who need them, to use them.
>>
>> (2) those who don't care about them, to totally ignore
>> them.
>>
>> (3) and those who utterly *HATE* them, to write a simply
>> little function which will strip them from any and all
>> source code they might be forced to maintain.
>
> Awwww. Isn't it cute, how he thinks that comments are easier to remove
> than other elements equally well defined in the grammar?
You're right in that neither task is that trivial.
I can remove comments by writing a tokeniser which scans Python source
and re-outputs tokens one at a time. Such a tokeniser normally ignores
comments.
But to remove type hints, a deeper understanding of the input is needed.
I would need a parser rather than a tokeniser. So it is harder.
Both methods would fail with source code that exists as a string
constant (for exec() for example), or source code that is synthesised at
runtime.
--
bart
More information about the Python-list
mailing list