11# Copyright (c) Microsoft Corporation. All rights reserved.
22# Licensed under the MIT License.
33
4- from . dialog_set import DialogSet
4+
55from .dialog_state import DialogState
66from .dialog_turn_result import DialogTurnResult
77from .dialog_reason import DialogReason
8+ from .dialog import Dialog
89from botbuilder .core .turn_context import TurnContext
910
10-
1111class DialogContext ():
12- def __init__ (self , dialogs : DialogSet , turn_context : TurnContext , state : DialogState ):
12+ def __init__ (self , dialog_set : object , turn_context : TurnContext , state : DialogState ):
1313 if dialogs is None :
1414 raise TypeError ('DialogContext(): dialogs cannot be None.' )
15+ # TODO: Circular dependency with dialog_set: Check type.
1516 if turn_context is None :
1617 raise TypeError ('DialogContext(): turn_context cannot be None.' )
1718 self .__turn_context = turn_context ;
@@ -55,7 +56,7 @@ def active_dialog(self):
5556 :param:
5657 :return str:
5758 """
58- if (self .__stack & & self .__stack .size () > 0 ):
59+ if (self .__stack and self .__stack .size () > 0 ):
5960 return self .__stack [0 ];
6061 return None ;
6162
@@ -76,18 +77,17 @@ async def begin_dialog(self, dialog_id: str, options: object = None):
7677 " The dialog must be included in the current or parent DialogSet."
7778 " For example, if subclassing a ComponentDialog you can call add_dialog() within your constructor." % dialog_id );
7879 # Push new instance onto stack
79- instance = new DialogInstance ();
80- {
81- Id = dialogId ,
82- State = new Dictionary < string , object > (),
83- };
80+ instance = DialogInstance ()
81+ instance .id = dialog_id
82+ instance .state = []
8483
8584 stack .insert (0 , instance );
8685
8786 # Call dialog's BeginAsync() method
8887 return await dialog .begin_dialog (this , options );
8988
90- async def prompt (self , dialog_id : str , options : PromptOptions ) -> DialogTurnResult :
89+ # TODO: Fix options: PromptOptions instead of object
90+ async def prompt (self , dialog_id : str , options ) -> DialogTurnResult :
9191 """
9292 Helper function to simplify formatting the options for calling a prompt dialog. This helper will
9393 take a `PromptOptions` argument and then call.
@@ -103,7 +103,8 @@ async def prompt(self, dialog_id: str, options: PromptOptions) -> DialogTurnResu
103103
104104 return await begin_dialog (dialog_id , options );
105105
106- async def continue_dialog (self , dc : DialogContext , reason : DialogReason , result : object ):
106+
107+ async def continue_dialog (self , dc , reason : DialogReason , result : object ):
107108 """
108109 Continues execution of the active dialog, if there is one, by passing the context object to
109110 its `Dialog.continue_dialog()` method. You can check `turn_context.responded` after the call completes
@@ -120,9 +121,10 @@ async def continue_dialog(self, dc: DialogContext, reason: DialogReason, result:
120121 # Continue execution of dialog
121122 return await dialog .continue_dialog (self );
122123 else :
123- return new DialogTurnResult (DialogTurnStatus .Empty );
124+ return DialogTurnResult (DialogTurnStatus .Empty );
124125
125- async def end_dialog (self , context : TurnContext , instance : DialogInstance ):
126+ # TODO: instance is DialogInstance
127+ async def end_dialog (self , context : TurnContext , instance ):
126128 """
127129 Ends a dialog by popping it off the stack and returns an optional result to the dialog's
128130 parent. The parent dialog is the dialog that started the dialog being ended via a call to
@@ -146,7 +148,7 @@ async def end_dialog(self, context: TurnContext, instance: DialogInstance):
146148 # Return result to previous dialog
147149 return await dialog .resume_dialog (self , DialogReason .EndCalled , result );
148150 else :
149- return new DialogTurnResult (DialogTurnStatus .Complete , result );
151+ return DialogTurnResult (DialogTurnStatus .Complete , result );
150152
151153
152154 async def cancel_all_dialogs (self ):
@@ -170,7 +172,7 @@ async def find_dialog(self, dialog_id: str) -> Dialog:
170172 :return:
171173 """
172174 dialog = dialogs .find (dialog_id );
173- if (not dialog & & parent != None ):
175+ if (not dialog and parent != None ):
174176 dialog = parent .find_dialog (dialog_id );
175177 return dialog ;
176178
@@ -201,16 +203,16 @@ async def reprompt_dialog(self):
201203 raise Exception ("DialogSet.reprompt_dialog(): Can't find A dialog with an id of '%s'." % active_dialog .id );
202204
203205 # Ask dialog to re-prompt if supported
204- await dialog .reprompt_dialog (context , active_dialog );
206+ await dialog .reprompt_dialog (context , active_dialog )
205207
206208 async def end_active_dialog (reason : DialogReason ):
207209 instance = active_dialog ;
208210 if instance != None :
209211 # Look up dialog
210- dialog = find_dialog (instance .id );
212+ dialog = find_dialog (instance .id )
211213 if not dialog :
212214 # Notify dialog of end
213- await dialog .end_dialog (context , instance , reason );
215+ await dialog .end_dialog (context , instance , reason )
214216
215217 # Pop dialog off stack
216- stack .pop ());
218+ stack .pop ()
0 commit comments