Type checking in python?
Eric Hopper
hopper at omnifarious.mn.org
Tue Jul 18 19:59:42 EDT 2000
In article <20000718231047.D4283 at xs4all.nl>, Thomas Wouters
<thomas at xs4all.net> wrote:
>
> Well, I've more than once written a debug object that behaved like
> another object but with debug output. Without subclassing, because I
> would've had to override all methods anyway, and I didn't want the debug
> class to *do* anything.
This doesn't sound like a time to make use of generic programming. It
sounds like a time for Python's incredibly wonderful reflection
capabilities. Especially if you've done it more than once.
> If you insist on type-checking, do it the interface-way:
>
> getattr(object, "required_method") getattr(object, "required_datatype")
> [etc]
*shudder*
> 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.
--
Eric Hopper (hopper at omnifarious.mn.org) (http://www.omnifarious.org/~hopper)
More information about the Python-list
mailing list