[Python-Dev] Validators (was Re: Python-Dev Digest, Vol 9, Issue 17)

Isaac ishnigarrab at earthlink.net
Mon Apr 5 22:29:58 EDT 2004


Josiah Carlson wrote:

>Isaac,
>
>  
>
>>>Please note that you seem to be using the syntax ``type: variable''.
>>>We've settled on using ``variable: type'' instead.  (How to express
>>>types is quite a different story...)
>>>
>>>      
>>>
>>I haven't been following the thread on the subject much at all, I've 
>>just heard some rumbling about introducing static typing into python, 
>>    
>>
>
>Python is not going to have static typing as a part of the base language,
>so worry not.
>
>  
>
>>and frankly I'm a bit wary about the whole thing. I was just thinking 
>>that in keeping with python's dynamic nature that something more like a 
>>generalized way of validating the _nature_ of something as opposed to 
>>it's underlying *type* would be more appropriate. It's just that it 
>>    
>>
>
>How do you propose to get at the "nature" of what an object is? 
>Currently in Python, we really only have types to determine what an
>object is.  With that, we /can/ do per-call checks on the types of the
>input, heck, if we're smart, we can even do polymorphism.  Such a
>solution is doable in current Python with various approaches.  Making a
>decorator that would handle type checking and polymorphism has been
>provided here already, or we can go a class-based route to do the same
>thing, though not nearly as neat.
>
>Still, what do you mean by the "nature" of what something is?
>
> - Josiah
>  
>
Nature was a horrible word for me to use; what I was trying to convey 
was that there are so many mays to analyze an object besides just the 
type (which I assume directly refers to the return value of type(object) 
as opposed to some loose concept of 'type' as in style) of the object. 
Like some of the examples I gave earlier, in_range, i.e.:

    def in_range(*args):
       r = range(*args)
       def partial(n):
          if n in r:
             return n
          else:
             raise TypeError
       return partial

    def func(a: in_range(10)): pass

which is very different from pure type checking which I assume would be:

    def func(a: int): pass

which simply translates to an 'isinstance(a, int)' call, where 'a' is a 
variable and 'int' is a type object.



More information about the Python-Dev mailing list