Type checking in python?

Thomas Wouters thomas at xs4all.net
Wed Jul 19 04:14:17 EDT 2000


On Tue, Jul 18, 2000 at 05:59:42PM -0600, Eric Hopper wrote:
> In article <20000718231047.D4283 at xs4all.nl>, Thomas Wouters
> <thomas at xs4all.net> wrote:
> > If you insist on type-checking, do it the interface-way:
> > 
> > getattr(object, "required_method") getattr(object, "required_datatype")
> > [etc]

> 	*shudder*

Well, that's why noone does it. Just using the object and assuming *some*
clue in the programmer is what most people do, and you know ? It works
pretty well, really.

> > Scoping is incredibly simple in Python. There's the local scope, and the
> > global scope ;) It might take some getting used to if you're used to
> > magic or explicit scopes, but it's definately very simple ;)
> 
> It is very simple.  I would prefer more nesting of scopes though.  In
> particular, lambda expressions should have the local scope they're
> declared in as their global scope.  I understand why they don't.  It's
> because of how references to variables inside functions are optimized.

Nah, that can be turned off or worked around. The problem is that Python has
no nested scopes period. local/global *look* nested, but they really aren't,
they're just two seperate namespace-pointers that might point to the same
one.

For Python to get nested scopes it would, for one, have to deal with cyclic
garbage first, and then be rewritten do to nested scopes. Quite a large
rewrite. I think the 'lambda x, y=y, z=z' trick works good enough. If you
need more complicated lambda's, you don't need a lambda, you need a class.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list