@@ -416,17 +416,19 @@ const CALL_PYTHON_FUNCTION = {
416416 }
417417 } ,
418418 renameMethodCaller : function ( this : CallPythonFunctionBlock , newName : string ) : void {
419+ // renameMethodCaller is called when the method or event definition block in the same module is modified.
419420 if ( this . mrcFunctionKind == FunctionKind . EVENT ) {
420421 this . setFieldValue ( newName , FIELD_EVENT_NAME ) ;
421422 } else if ( this . mrcFunctionKind == FunctionKind . INSTANCE_WITHIN ) {
422- // TODO(lizlooney): What about this.mrcActualFunctionName? Does it need to be updated?
423423 this . setFieldValue ( newName , FIELD_FUNCTION_NAME ) ;
424+ // mrcActualFunctionName does not need to be updated because it is not used for INSTANCE_WITHIN.
424425 }
425426 } ,
426427 mutateMethodCaller : function (
427428 this : CallPythonFunctionBlock ,
428429 methodOrEvent : commonStorage . Method | commonStorage . Event
429430 ) : void {
431+ // mutateMethodCaller is called when the method or event definition block in the same module is modified.
430432 if ( this . mrcFunctionKind == FunctionKind . EVENT ) {
431433 const event = methodOrEvent as commonStorage . Event ;
432434 this . mrcArgs = [ ] ;
@@ -440,7 +442,7 @@ const CALL_PYTHON_FUNCTION = {
440442 const method = methodOrEvent as commonStorage . Method ;
441443 this . mrcReturnType = method . returnType ;
442444 this . mrcArgs = [ ] ;
443- // We don't include the arg for the self argument because we don't want a socket for it.
445+ // We don't include the arg for the self argument because we don't need a socket for it.
444446 for ( let i = 1 ; i < method . args . length ; i ++ ) {
445447 this . mrcArgs . push ( {
446448 name : method . args [ i ] . name ,
@@ -464,6 +466,7 @@ const CALL_PYTHON_FUNCTION = {
464466 return components ;
465467 } ,
466468 onLoad : function ( this : CallPythonFunctionBlock ) : void {
469+ // onLoad is called for each CallPythonFunctionBlock when the blocks are loaded in the blockly workspace.
467470 const warnings : string [ ] = [ ] ;
468471
469472 // If this block is calling a component method, check that the component
@@ -509,7 +512,7 @@ const CALL_PYTHON_FUNCTION = {
509512 warnings . push ( 'This block calls a method on a component that no longer exists.' ) ;
510513 }
511514
512- // TODO(lizlooney): Could the component's method have change?
515+ // TODO(lizlooney): Could the component's method have change or been deleted ?
513516 }
514517
515518 // If this block is calling a robot method, check that the robot method
@@ -526,32 +529,23 @@ const CALL_PYTHON_FUNCTION = {
526529 if ( robotMethod . blockId === this . mrcOtherBlockId ) {
527530 foundRobotMethod = true ;
528531
529- // If the function name has changed, we can fix this block.
530532 if ( this . mrcActualFunctionName !== robotMethod . pythonName ) {
531533 this . mrcActualFunctionName = robotMethod . pythonName ;
532534 }
533535 if ( this . getFieldValue ( FIELD_FUNCTION_NAME ) !== robotMethod . visibleName ) {
534536 this . setFieldValue ( robotMethod . visibleName , FIELD_FUNCTION_NAME ) ;
535537 }
536538
537- // Other things are more difficult.
538- if ( this . mrcReturnType !== robotMethod . returnType ) {
539- warnings . push ( 'This block calls a method whose return type has changed.' ) ;
540- }
541- if ( this . mrcArgs . length !== robotMethod . args . length - 1 ) {
542- warnings . push ( 'This block calls a method whose arguments have changed.' ) ;
543- } else {
544- for ( let i = 1 ; i < robotMethod . args . length ; i ++ ) { // Skip the self argument.
545- if ( this . mrcArgs [ i - 1 ] . name != robotMethod . args [ i ] . name ) {
546- warnings . push ( 'This block calls a method whose arguments have changed.' ) ;
547- break ;
548- }
549- if ( this . mrcArgs [ i - 1 ] . type != robotMethod . args [ i ] . type ) {
550- warnings . push ( 'This block calls a method whose arguments have changed.' ) ;
551- break ;
552- }
553- }
539+ this . mrcReturnType = robotMethod . returnType ;
540+ this . mrcArgs = [ ] ;
541+ // We don't include the arg for the self argument because we don't need a socket for it.
542+ for ( let i = 1 ; i < robotMethod . args . length ; i ++ ) {
543+ this . mrcArgs . push ( {
544+ name : robotMethod . args [ i ] . name ,
545+ type : robotMethod . args [ i ] . type ,
546+ } ) ;
554547 }
548+ this . updateBlock_ ( ) ;
555549
556550 // Since we found the robot method, we can break out of the loop.
557551 break ;
0 commit comments