[Types-sig] Static typing: Towards closure?

scott scott@chronis.pobox.com
Thu, 20 Jan 2000 21:51:36 -0500


On Thu, Jan 20, 2000 at 09:35:49PM -0500, Guido van Rossum wrote:
> Scott suggests a perhaps more Pythonic way to spell a typecase
> statement:
> 
[...]
> 
> Thinking further, I realize that we *already* have a function that
> does this: isinstance().  The rule could be that if the test in an
> 'if' or 'elif' statement hasd the form isinstance(<dottedname1>,
> <dottedname2>) where dottedname1 is a statically known variable and
> dottedname2 is a statically known type name, the type of <dottedname1>
> is considered to be <dottedname1> in the corresponding block.
> 
> This might even let us write things like
> 
> if isinstance(foo, [long]): ...
> 
> or
> 
> if isinstance(bar, int|long|float): ...
> 
> if we are creative with operator overloading -- although I don't see a
> lot of use for the latter since the whole point of a typecase is to
> disambiguate unions...
> 
> Potential problem:
> 
> # x is a global
> decl x: int|float
> 
> if isinstance(x, int):
>    ...call some function which as a side effect changes x into a float...
>    ...use x as an int... # ERROR, but not detected statically

Do you mean to add the word 'isinstance' as a keyword in the grammar,
or to use the builtin function?  As a keyword, it seems very tricky to
make it call some internal 'isinstance' that is no longer available as
a builtin.  As a builtin, we have lots of problems:

if sys.argv[1:] or isinstance(x, int):

if isinstance(x, int) == 1:

etc.

hmm.

scott