Shed Skin - Does it break any Python assumptions?

Jean-Paul Calderone exarkun at divmod.com
Mon Dec 18 09:57:42 EST 2006


On Mon, 18 Dec 2006 08:07:59 -0600, skip at pobox.com wrote:
>I just noticed the announcement of Shed Skin 0.0.16 on Freshmeat with this
>(partial) change announcement:
>
>    Changes: frozenset was added. time.sleep now works on Win32.
>
>Given Python's highly dynamic nature it's unclear to me how Shed Skin could
>know enough about the semantics of time.sleep to know whether or not it's
>broken on Win32.

Actually, this could just mean that on Windows, there is no suitable
implementation of the stdlib function time.sleep, and so attempts to
use it will result in bad behavior of some sort.

It does not necessarily mean that ShedSkin is doing anything which
might prevent the attribute `sleep' from being rebound on a module
importable as `time' to some other function which behaves differently.

Of course, what is not necessarily the case may still be the case. ;)

>This suggests that to gain speedups it probably implements
>a more static language than Python.  For example, does Shed Skin handle a
>case like this?
>
>    >>> import time
>    >>> time.sleep(1)
>    >>> def _sleep(n):
>    ...   print "sleeping for", n, "seconds"
>    ...   time._sleep(n)
>    ...
>    >>> time._sleep = time.sleep
>    >>> time.sleep = _sleep
>    >>> time.sleep(1)
>    sleeping for 1 seconds
>
>What does this phrase in the announcement mean?  "... pure but implicitly
>statically typed Python ...".  Where does the static typing begin and end?
>Can one module tweak another module's attributes?  Can a class's attributes
>be modified from outside the class?  What about the attributes of a class
>instance?

>From the ShedSkin README:

Do not use:
  ...
  -reflection (getattr, hasattr), eval, or other really dynamic stuff
  ...

I would say that the example you presented above falls into the "really
dynamic stuff" category. ;)

And in fact, attempting to compile a program somewhat like the one above
results in this:

exarkun at charm:~/Scratch/Source/shedskin-0.0.16$ make
g++ -O3  -I./lib ./lib/builtin.cpp ./lib/time.cpp foo.cpp -lgc  -o foo
foo.cpp: In function ‘int __foo__::__main()’:
foo.cpp:6: error: assignment of function ‘void __time__::sleep(double)’
foo.cpp:6: error: cannot convert ‘unsigned int ()(unsigned int)’ to ‘void ()(double)’ in assignment
make: *** [foo] Error 1
exarkun at charm:~/Scratch/Source/shedskin-0.0.16$         

So yes, it seems that what ShedSkin supports is pretty distant from what
a seasoned Python developer might expect, aside from syntactic constructs.

Jean-Paul



More information about the Python-list mailing list