poppopjmp / shedskin

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

class var type infer error #136

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

Correct if uncomment the Logger.Init() in the last 2 lines
Logger.LoggerFile  should be typed as file* in both cases instead of void*

test case:
class Logger(object):
    debug = False
    LoggerFile = None

    @staticmethod
    def Init( LoggerFileName = 'log' ):
        Logger.LoggerFile = open( LoggerFileName, 'w' )

    @staticmethod
    def Print( str, Force = False ):
        if Logger.debug == True or Force == True:
            print str
        if Logger.LoggerFile != None:
            Logger.LoggerFile.write( str + '\n' )

if __name__ == "__main__":
    #Logger.Init()
    Logger.Print('asdf')

Original issue reported on code.google.com by jason.mi...@gmail.com on 15 Jun 2011 at 2:52

GoogleCodeExporter commented 8 years ago
thanks for reporting!

I'm afraid it's a bit tricky to deal with this like cpython does, and it's just 
how shedskin works at the moment. if 'Init' is not called, LoggerFile is always 
None, gets a type of 'void *', and this doesn't have a 'write' method. you'll 
have to puzzle a bit to get to work. for example if you're always under UNIX 
you could use open('/dev/null'). or perhaps nicer, always call Init, and in 
there do something like this:

Logger.LoggerFile = open(..) if loggerFileName else None

Original comment by mark.duf...@gmail.com on 15 Jun 2011 at 9:25

GoogleCodeExporter commented 8 years ago
I think THE LoggerFile  should be set to file*, because file* can accomondate  
None(NULL). Otherwise can't.
Right?

Jason

Original comment by jason.mi...@gmail.com on 15 Jun 2011 at 9:48

GoogleCodeExporter commented 8 years ago
its type should be file* yes, otherwise LoggerFile.write will not be accepted 
by the C++ compiler. and it's fine to assign None(NULL) to file* or any 
pointer-type.

Original comment by mark.duf...@gmail.com on 15 Jun 2011 at 10:02