cy99 / shedskin

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

Exception subclasses don't always inherit Exception.__init__ #132

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
fake.py:
class Error(Exception):
    pass

class BadError(Exception):
    pass

def exception_error():
    raise Error("AOE")
    raise BadError("AOE")

if __name__=='__main__':
    Error("OE")
    BadError()
    exception_error()

------------

So Error() is fine because the __main__ calls the Error(string) init, but 
BadError() crashes shedskin like so:

*** SHED SKIN Python-to-C++ Compiler 0.7.1 ***
Copyright 2005-2010 Mark Dufour; License GNU GPL version 3 (See LICENSE)

[analyzing types..]
0%
Traceback (most recent call last):
  File "/usr/local/bin/shedskin", line 3, in <module>
    shedskin.main()
  File "/usr/local/lib/python2.6/dist-packages/shedskin/__init__.py", line 93, in main
    start()
  File "/usr/local/lib/python2.6/dist-packages/shedskin/__init__.py", line 86, in start
    infer.analyze(name)
  File "/usr/local/lib/python2.6/dist-packages/shedskin/infer.py", line 912, in analyze
    iterative_dataflow_analysis()
  File "/usr/local/lib/python2.6/dist-packages/shedskin/infer.py", line 655, in iterative_dataflow_analysis
    propagate()
  File "/usr/local/lib/python2.6/dist-packages/shedskin/infer.py", line 144, in propagate
    cpa(node, worklist)
  File "/usr/local/lib/python2.6/dist-packages/shedskin/infer.py", line 372, in cpa
    actuals_formals(callfunc, func, callnode, dcpa, cpa, objtype+c, worklist)
  File "/usr/local/lib/python2.6/dist-packages/shedskin/infer.py", line 424, in actuals_formals
    formalnode = getgx().cnode[func.vars[formal], dcpa, cpa]
KeyError: ((function (class BadError, '__init__'), 'self'), 1, 1)

Sorry about all these issues, I swear I'm doing something that's useful for 
shedskin. I'm a little past halfway into porting binascii.

Original issue reported on code.google.com by fahhem%r...@gtempaccount.com on 3 Mar 2011 at 9:20

GoogleCodeExporter commented 9 years ago
auwf, thanks! I'm actually very happy you report you this, because this is 
really basic code that should work.. no time unfortunately this weekend, but 
I'm planning on looking into it next week.

Original comment by mark.duf...@gmail.com on 4 Mar 2011 at 11:15

GoogleCodeExporter commented 9 years ago
in trying to reproduce this without relying on builtin exception classes, I ran 
into the following, possibly related problem:

class MyBaseException:
    def __init__(self, msg=None):
        self.msg = msg
class MyException(MyBaseException): pass
class MyStandardError(MyException): pass
class MyBadError(MyException):
    pass

if __name__=='__main__':
    MyStandardError()
    MyBadError()

I guess shedskin still has some problems with deeper inheritance hierarchies.. 

Original comment by mark.duf...@gmail.com on 18 Mar 2011 at 8:17

GoogleCodeExporter commented 9 years ago
minimized the first fragment as follows. strangely copying the Exception 
classes into here makes it compile.

class BadError(Exception):
    pass

if __name__=='__main__':
    BadError()
    BadError("AOE")

Original comment by mark.duf...@gmail.com on 18 Mar 2011 at 8:22

GoogleCodeExporter commented 9 years ago
okay, I spent a few hours debugging this today, and I think I understand the 
cause of problem 1. unfortunately the obvious fix leads to other problems, so I 
will have to look a bit further.. :-)

Original comment by mark.duf...@gmail.com on 18 Mar 2011 at 3:21

GoogleCodeExporter commented 9 years ago
so I had another look after coffee the next morning, and committed a fix:

http://gitorious.org/shedskin/mainline/commit/d29197767ce46966567b7331b57ff2744d
b1d6ce

I just love throwing away code! :D

unfortunately I can't close this issue because of the other problem it made me 
find.. so I will look into that next.

Original comment by mark.duf...@gmail.com on 19 Mar 2011 at 10:50

GoogleCodeExporter commented 9 years ago
btw, how's your project going..? do you have something interesting (and large?) 
yet that we might add to examples/? :-)

Original comment by mark.duf...@gmail.com on 19 Mar 2011 at 10:58

GoogleCodeExporter commented 9 years ago
alright, the other problem is fixed now too. please confirm that I can close 
this issue! :D

Original comment by mark.duf...@gmail.com on 19 Mar 2011 at 6:37

GoogleCodeExporter commented 9 years ago

Original comment by mark.duf...@gmail.com on 23 Mar 2011 at 7:39

GoogleCodeExporter commented 9 years ago
I'm too impatient, I know.. ;) please reopen the issue if you run into anything 
similar.

Original comment by mark.duf...@gmail.com on 23 Mar 2011 at 8:07

GoogleCodeExporter commented 9 years ago
No, sorry. Shedskin's library limitations are very restrictive for me. I'll be 
opening a separate ticket to discuss my solution for that.

Original comment by fahh...@gmail.com on 19 Apr 2011 at 11:28