Explicit variable declaration
Steve Holden
steve at holdenweb.com
Wed Apr 23 08:01:25 EDT 2008
Filip Gruszczyński wrote:
>> You mean the type? Not in 2.x, but in 3.x, there are function
>> annotations:
>>
>> def a_function(arg1: int, arg2: str) -> None: pass
>
> Nope, I don't like types ;-) 3.x seems pretty revolutionary, and this
> typing can be appreciated by some people.
>
>> Declaring what about them? If you mean declaring the type, remember
>> that Python deliberately allows any name to be bound to any object;
>> type declarations can't be enforced without losing a lot of the power
>> of Python.
>
> Just declaring, that they exist. Saying, that in certain function
> there would appear only specified variables. Like in smalltalk, if I
> remember correctly.
>
Icon has (had?) the same feature: if the "local" statement appeared then
the names listed in it could be assigned in the local namespace, and
assignment to other names wasn't allowed.
A lot of people assume that's what the __slots__ feature of the new
object model is for, but it isn't: it's actually a memory conservation
device for circumstances when millions of objects must be created in an
application.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list