Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PythonCommand : Fix repr() and str() for variables dict #5656

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Fixes
-----

- Viewer : Fixed context handling bug in the shader view (#5654).
- PythonCommand : Fixed misleading results for `repr( variables )` and `str( variables )`, which would suggest the dictionary was empty when it was not.

1.3.11.0 (relative to 1.3.10.0)
========
Expand Down
10 changes: 10 additions & 0 deletions python/GafferDispatch/PythonCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ def __getitem__( self, key ) :
self.__update()
return dict.__getitem__( self, key )

def __repr__( self ) :

self.__update()
return dict.__repr__( self )

def __str__( self ) :

self.__update()
return dict.__str__( self )

def __update( self ) :
frame = self.__context.get( "frame", "NO FRAME" )

Expand Down
10 changes: 10 additions & 0 deletions python/GafferDispatchTest/PythonCommandTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,5 +428,15 @@ def testContextModificationsDontLeak( self ) :

self.assertEqual( Gaffer.Context.current(), Gaffer.Context() )

def testVariablesRepr( self ) :

command = GafferDispatch.PythonCommand()
command["variables"].addChild( Gaffer.NameValuePlug( "testKey", "testValue" ) )
command["command"].setValue( "self.variablesStr = str( variables ); self.variablesRepr = repr( variables )" )
command["task"].execute()

self.assertEqual( command.variablesStr, str( { "testKey" : "testValue" } ) )
self.assertEqual( command.variablesRepr, repr( { "testKey" : "testValue" } ) )

if __name__ == "__main__":
unittest.main()
Loading