dict and set comprehensions wrapping

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
rivvil
Regular
Posts: 26
Joined: Fri Feb 20, 2015 3:05 pm
Location: Russia
Contact:

dict and set comprehensions wrapping

#1 Post by rivvil » Sat Mar 07, 2015 8:04 am

Hello.
Recently I found out that Python dict and set comprehensions used within .rpy scripts do not produce RevertableDict and RevertableSet objects. In contrast to this behavior list comprehensions create instances of RevertableList.
Personally I would prefer if all kinds of comprehensions will produce "revertable objects". It seems to be more consistent approach as well.
So, is this intentional difference between list and set/dict comprehensions?

EDIT:
For now, by analogy with existent wrappers I've added two methods into WrapNode class (renpy/python.py, line 329):

Code: Select all

def visit_DictComp(self, n):
    return ast.Call(
        func = ast.Name(
            id="__renpy__dict__",
            ctx=ast.Load()
            ),
        args = [ self.generic_visit(n) ],
        keywords = [ ],
        starargs = None,
        kwargs = None)

def visit_SetComp(self, n):
    return ast.Call(
        func = ast.Name(
            id="set",
            ctx=ast.Load()
            ),
        args = [ self.generic_visit(n) ],
        keywords = [ ],
        starargs = None,
        kwargs = None)
It seems to be working. But I'm not an expert in pythonic AST manipulations. So, I'm using this technique at my own risk :)

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: dict and set comprehensions wrapping

#2 Post by PyTom » Sat Mar 07, 2015 11:26 am

This is absolutely correct, and somewhat embarrassing oversight on my part. I've merged your code into Ren'Py, it will be in the next 6.99 prerelease.

Thank you!
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

rivvil
Regular
Posts: 26
Joined: Fri Feb 20, 2015 3:05 pm
Location: Russia
Contact:

Re: dict and set comprehensions wrapping

#3 Post by rivvil » Sat Mar 07, 2015 2:35 pm

You're welcome. Glad to help :)

Post Reply

Who is online

Users browsing this forum: No registered users