kgashok / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

type( object ) is not supported. #126

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In python, often developers will use the type() function to verify the type of 
objects. Example:

def make_negative(interger):
    if type(interger) != type(0):
        raise Exception('"interger" is not an interger!')
    else:
        return (-1)*interger

On another note: I'd really like to help out with this project, but I am only 
proficient in python. If there is anything I can do to help out, leave a note 
here and I'll try my best to help out.

Great project you've got here!

Original issue reported on code.google.com by sears....@gmail.com on 17 Jan 2011 at 10:44

GoogleCodeExporter commented 8 years ago
thanks for reporting.. but how would type() be useful, if the thing that goes 
into it has to be statically typed (or shedskin won't compile the code 
anyway)..? 

Original comment by mark.duf...@gmail.com on 18 Jan 2011 at 5:05

GoogleCodeExporter commented 8 years ago
Hi,
With my tests, OptParser for example uses type() to know what to return. There 
is a "type" module that defines some special case (None => NoneType...)

Without type() function, lot of modules cannot be compiler (or modified to be 
compatible)

Original comment by Metal3d on 19 Jan 2011 at 1:04

GoogleCodeExporter commented 8 years ago
yes, and that's fine with me.. :-) shedskin really isn't meant to compile 
arbitrary code. it's a tool that allows you to write really fast code, as long 
as you're willing to sacrifice some python features.. in many cases, shedskin 
-e allows you to incorporate this into larger, unrestricted, programs. several 
programs in the example set use pygame, multiprocessing, pygame in this way.. 

Original comment by mark.duf...@gmail.com on 19 Jan 2011 at 1:13

GoogleCodeExporter commented 8 years ago
I meant pygame, multiprocessing and pygtk..

Original comment by mark.duf...@gmail.com on 19 Jan 2011 at 1:14

GoogleCodeExporter commented 8 years ago
It's ok, but this can be usefull to have some "types" instrospection abilities 
I guess... no ?

Original comment by Metal3d on 19 Jan 2011 at 1:17

GoogleCodeExporter commented 8 years ago
yeah, but because of the static typing restriction, their use will always 
remain rather limited.. they may be useful when dealing with inheritance 
hierarchies (to determine which subclass are we dealing with, for a given 
static base class), but that's about it. 'isinstance' actually already works 
for this, and I guess we could implement 'type' in the same way.. 

Original comment by mark.duf...@gmail.com on 19 Jan 2011 at 1:25

GoogleCodeExporter commented 8 years ago
If ShedSkin wanted to be really clever it could compile the function to 
something like:

def make_negative(object interger):
    raise Exception('"interger" is not an interger!')

def make_negative(int interger):
    return (-1)*interger

Not sure where that would fit on the doable scale though, along with being low 
on the wanted scale.

Original comment by testo....@gmail.com on 15 Feb 2011 at 8:24

GoogleCodeExporter commented 8 years ago
shedskin supported generic functions/classes a long time ago, but I ended up 
ripping it out (and never regretted that decision), because it complicated lots 
of things and was never very useful, or it could easily be worked around..

in any case, splitting functions based on how they use 'type' or 'isinstance' 
sounds like it's too clever.. :-) 

Original comment by mark.duf...@gmail.com on 27 Feb 2011 at 12:45