[Python-ideas] Delay evaluation of annotations

Chris Angelico rosuav at gmail.com
Thu Sep 22 17:39:43 EDT 2016


On Fri, Sep 23, 2016 at 7:33 AM, אלעזר <elazarg at gmail.com> wrote:
> On Fri, Sep 23, 2016 at 12:18 AM Chris Angelico <rosuav at gmail.com> wrote:
>>
>> # Recursion in functions
>> def spam():
>>     return spam()
>
>
> I just note that it *is* surprising, for most users, that you can't be sure
> that this is a recursion, yet. So it if you want a trusted-upon recursion
> you should write
>
> # spam:
> def spam():
>     def spam():
>         return spam()
>     return spam()
>
>

Only surprising for people who want it _guaranteed_. It's the exact
same problem as this:

def helper(x):
    ...

def spaminate(x, y):
    helper(x)
    helper(y)

How do you know that a replacement helper hasn't been injected? You
don't... but you trust that people aren't normally going to do that,
and if they do, they're taking responsibility (maybe they're mocking
helper for testing).

ChrisA


More information about the Python-ideas mailing list