On 30 April 2015 at 14:33, Steven D'Aprano <steve@pearwood.info> wrote:
> On Thu, Apr 30, 2015 at 01:41:53PM +0200, Dima Tisnek wrote:
>> # internal vs external
>> @intify
>> def foo() -> int:
>> b = "42"
>> return b # check 1
>> x = foo() // 2 # check 2
>>
>> Does the return type apply to implementation (str) or decorated callable (int)?
>
> I would expect that a static type checker would look at foo, and flag
> this as an error. The annotation says that foo returns an int, but it
> clearly returns a string. That's an obvious error.
Is this per PEP, or just a guess?
I think PEP needs to be explicit about this.
> Normally local variables will have their type inferred from the
> operations done to them:
>
> s = arg[1:] # s has the same type as arg
Good point, should be mentioned in PEP.
Technically, type can be empty list, mixed list or custom return type
for overloaded __getitem__ that accepts slices.
I'm sorry if I was not clear. My question was how should type of
ephemeral `x` be specified.
In other words, can types be specified on anything inside a comprehension?
Stub is better (required?) because it allows to specify types of
attributes that are not assigned in class scope, but that are expected
to be there as result of __init__ or because it's a C extension.
An example in PEP would be good.