Page 1 of 1

RenPy reports a different Error during compiling.

Posted: Thu Oct 03, 2013 7:45 am
by xela

Code: Select all

def foo():
    spam = 'eggs'
    def bar():
        print spam
    del spam

Python:
SyntaxError: can not delete variable 'spam' referenced in nested scope
RenPy:
AttributeError: 'NoneType' object has no attribute 'decode'
Python reports it in a way that is a whole load less confusing.

Re: RenPy reports a different Error during compiling.

Posted: Mon Oct 07, 2013 8:34 pm
by jesusalva
First, Renpy ± said that:
The value of your variable Python Block Outcome A RenPy Parser Variable responsible for Python Blocks is None.
basically, your variable don't exists. RenPy cannot decode something that don't exist!
about Python... placing a "del" function appear a bit... troublesome.
I use the following to delete a variable:

Code: Select all

    spam = None
    renpy.free_memory()
But deleting the variable IS NOT required.

I don't think that placing "print" command in renpy is a safe move. Ren'Py rarely use a Terminal as base.
So, that "print" command can return an error, also.

Oh yeah, python said
SyntaxError: can not delete variable 'spam' referenced in nested scope
It means that (of course) it cannot delete the variable, because the scope where it is. Or, better saying, RenPy don't support this command (I'm not sure about this).

You could change the code to:

Code: Select all

def foo():
    spam = 'eggs'
    def bar():          # Defining INSIDE a definition? caution, this can lead to errors.
        print spam     # I kept it here. It is not a very smart move, but...
    #del spam         # not this!
    spam = None
    renpy.free_memory()    # RenPy try free a bit of memory, and it is a NoneType variable, so it should clean.
Hmm... Hope that helped.

EDIT: strucked-out a lot of text, see my next reply.
OTHERS EDITS: fixed a bit of my writting. just some mistakes.

Re: RenPy reports a different Error during compiling.

Posted: Tue Oct 08, 2013 7:17 am
by xela
Thanks for the effort but I just tried to report an issue so someone might improve error reporting, I didn't actually have a nested function in my code and oversimplified in order not to post 2.5k lines of relevant code that noone would read anyway. I've also found four ways to avoid that problem (not deleting the variables was one of them :) ).

The original issue was here (method of a class):

Code: Select all

                a = self.girlmod
                b = self.girl.guard_relay['bar_event']['stats']
                self.girlmod = dict( (n, a.get(n, 0)+b.get(n, 0)) for n in set(a)|set(b) )
                del a
                del b
For some reason, both Python and RenPy throw the above mentioned errors here, only in pure python, you know exactly where to look for it but if this catches you in RenPy unawares, you might end up looking for it in your code for hours.

The code itself is sound, basically a one-liner for adding the two dictionaries with integer values together. We've ripped parts of the code from the game and ran it through IDLE, it seems that dictionary comprehensions in Python work very different from list comprehensions (Python PEP claims that they're very similar by the way) because similar list comprehensions NEVER throw nested scope errors or it's simply a bug in Python (some check they've forgot to remove from the compiler when they've added new possibilities).

PS: My point is that such errors are not always apparent and RenPy does a terrible job at catching them.

Re: RenPy reports a different Error during compiling.

Posted: Tue Oct 08, 2013 2:42 pm
by jesusalva
hmm... what is the PEP state? I mean, PEP mean "Project of Enhacementupgrade of Python" (Or something like that), was it an approved one? (Sorry for mistakes, I'm not american, thus, I can make more mistakes)

Remember: RenPy 6.15 run in Python2.7 (or used to), so, if that was tested with Python > 3.2, the *things* can be different.

Some of Python 3.* was included in Python 2.7. But I don't know very well what is the version number. I think that was 3.1 and 3.2, but I'm not sure about this.


Oh Yeah, if you wondering where the decode error is...

Code: Select all

  File "/home/username/Documentos/renpy/parser.py", line 114, in unicode_filename
    return fn.decode("latin-1")
AttributeError: 'NoneType' object has no attribute 'decode'

Linux-3.2.0-54-generic-pae-i686-with-debian-wheezy-sid
Ren'Py 6.15.2.281


Just if you are wondering why RenPy said "decoding error": it said the error in renpy parser, not in your python block. It didn't even looked at your code, it stopped in parser. if you read the full traceback, you can see it. That line says "If you want find the error, look in IDLE or similar".

So, that is why Python Error is less confusing: because Python read the code, RenPy don't.


What you've been reading in RenPy traceback is that it cannot read your Python Block.
I don't know if there is a way to fix that, for now, reading the last line in full traceback is enough.

P.S: I've censored my username in the traceback. That won't change nothing.

P.P.S: about your PS: RenPy didn't made a horrible job finding the error. It just found an error while preparing the code to be executated. I mean, if you see, the error appears when you end the "def", not when you call it. The error is in pre-start, that is ran in parser.py. When the error was found, it was "found" in the parser, not in the block. So it said "parser.py"'s error, not your Python Error.

And, if you don't understand my P.P.S, it is saying that the error was found while parser.py was running. So it think that it is a Parser.py error, what is half-true, there was an error in parser.py: the "fn" variable value was None. But that wasn't parser.py fault.
It can't execute your Python Block to see where the error is. So, it keep saying only the place where python block starts.

Re: RenPy reports a different Error during compiling.

Posted: Tue Oct 08, 2013 3:26 pm
by xela
LoL I actually got a decent laugh out of this error :)

How do you think RenPy knows there is an error without reading the python block first (or how does it know that the error is gone after "del a" is deleted)? Does it guess?

PEP: http://www.python.org/dev/peps/pep-0274/

Full Traceback:
I'm sorry, but an uncaught exception occurred.

While compiling python block starting at line 1 of game/library/classes - jobs.rpy.
AttributeError: 'NoneType' object has no attribute 'decode'

-- Full Traceback ------------------------------------------------------------

Full traceback:
File "D:\Dev\Dropbox\SimBro Dev\renpy-6.15.0-sdk\renpy\bootstrap.py", line 265, in bootstrap
renpy.main.main()
File "D:\Dev\Dropbox\SimBro Dev\renpy-6.15.0-sdk\renpy\main.py", line 207, in main
renpy.game.script.load_script() # sets renpy.game.script.
File "D:\Dev\Dropbox\SimBro Dev\renpy-6.15.0-sdk\renpy\script.py", line 177, in load_script
self.load_appropriate_file(".rpyc", ".rpy", dir, fn, initcode)
File "D:\Dev\Dropbox\SimBro Dev\renpy-6.15.0-sdk\renpy\script.py", line 441, in load_appropriate_file
if not self.load_file(dir, fn + source, initcode):
File "D:\Dev\Dropbox\SimBro Dev\renpy-6.15.0-sdk\renpy\script.py", line 320, in load_file
self.finish_load(stmts, initcode)
File "D:\Dev\Dropbox\SimBro Dev\renpy-6.15.0-sdk\renpy\script.py", line 403, in finish_load
self.update_bytecode()
File "D:\Dev\Dropbox\SimBro Dev\renpy-6.15.0-sdk\renpy\script.py", line 501, in update_bytecode
pos = e.offset)
File "D:\Dev\Dropbox\SimBro Dev\renpy-6.15.0-sdk\renpy\parser.py", line 39, in __init__
message = u"File \"%s\", line %d: %s" % (unicode_filename(filename), number, msg)
File "D:\Dev\Dropbox\SimBro Dev\renpy-6.15.0-sdk\renpy\parser.py", line 115, in unicode_filename
return fn.decode("latin-1")
AttributeError: 'NoneType' object has no attribute 'decode'

Windows-7-6.1.7601-SP1
Ren'Py 6.15.7.374
I am not saying error reporting here has to be fixed as a first priority, for devs it's not a priority at all I expect. It's just in case someone revisits that code, they might improve it.

Re: RenPy reports a different Error during compiling.

Posted: Tue Oct 08, 2013 3:49 pm
by jesusalva
I think that us aren't understanding ourselves. I don't know if you know what it is, but anyway, I'm going away.

Re: RenPy reports a different Error during compiling.

Posted: Tue Oct 08, 2013 4:32 pm
by xela
jesusalva wrote:wha... ISN'T THAT OBVIOUS?! (HeHeHe, sorry for the CAPS, I sort-of-like dramatic effects.)
No, you said compiler knows there is an error without reading the code, it's not obvious how that would work.
jesusalva wrote: RenPy Parser take your block and put it in a object variable, called "fn".
Then it prepares RenPy to recive the Python code. (maybe... with self.update_bytecode() )
it then decodes the Python Block.
fn stands for "file name" not code block.
jesusalva wrote: And, read, sometimes, is different from execute. I won't give you an example, or you will become more confused.
The only thing I am confused about is your insane interpretation of cause of this error. Read is by way always different from execute.
jesusalva wrote: decode(), that, since I remember, comes with renpy, and etc.
It's a Python string method. Quite a common one actually.
jesusalva wrote: if fn is not None:
return fn.decode("latin-1")
else:
raise Exception("Your Python block cannot be decoded, due an unknow error.\nPlease, try running it at IDLE or other python-reading progam.")
Calling a string method on None object is caused by the code leading to it (file name is supplied as None to the function). Your understanding of the issue is not enough to make a call on how difficult would it be to enable RenPy to report this error similarly to IDLE so don't pretend like it is.