8000 pylint and black changes. No logic changes. (#427) · itsmokha/botbuilder-python@9ed74df · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ed74df

Browse files
tracyboehreraxelsrz
authored andcommitted
pylint and black changes. No logic changes. (microsoft#427)
1 parent 57fff2e commit 9ed74df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+829
-646
lines changed

samples/01.console-echo/adapter/console_adapter.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async def send_activities(self, context: TurnContext, activities: List[Activity]
116116
raise TypeError(
117117
"ConsoleAdapter.send_activities(): `context` argument cannot be None."
118118
)
119-
if type(activities) != list:
119+
if not isinstance(activities, list):
120120
raise TypeError(
121121
"ConsoleAdapter.send_activities(): `activities` argument must be a list."
122122
)
@@ -130,24 +130,27 @@ async def next_activity(i: int):
130130

131131
if i < len(activities):
132132
responses.append(ResourceResponse())
133-
a = activities[i]
133+
activity = activities[i]
134134

135-
if a.type == "delay":
136-
await asyncio.sleep(a.delay)
135+
if activity.type == "delay":
136+
await asyncio.sleep(activity.delay)
137137
await next_activity(i + 1)
138-
elif a.type == ActivityTypes.message:
139-
if a.attachments is not None and len(a.attachments) > 0:
138+
elif activity.type == ActivityTypes.message:
139+
if (
140+
activity.attachments is not None
141+
and len(activity.attachments) > 0
142+
):
140143
append = (
141144
"(1 attachment)"
142-
if len(a.attachments) == 1
143-
else f"({len(a.attachments)} attachments)"
145+
if len(activity.attachments) == 1
146+
else f"({len(activity.attachments)} attachments)"
144147
)
145-
print(f"{a.text} {append}")
148+
print(f"{activity.text} {append}")
146149
else:
147-
print(a.text)
150+
print(activity.text)
148151
await next_activity(i + 1)
149152
else:
150-
print(f"[{a.type}]")
153+
print(f"[{activity.type}]")
151154
await next_activity(i + 1)
152155
else:
153156
return responses

samples/01.console-echo/main.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22
# Licensed under the MIT License.
33

44
import asyncio
5-
from botbuilder.core import TurnContext, ConversationState, UserState, MemoryStorage
6-
from botbuilder.schema import ActivityTypes
75

86
from adapter import ConsoleAdapter
97
from bot import EchoBot
108

119
# Create adapter
12-
adapter = ConsoleAdapter()
13-
bot = EchoBot()
10+
ADAPTER = ConsoleAdapter()
11+
BOT = EchoBot()
1412

15-
loop = asyncio.get_event_loop()
13+
LOOP = asyncio.get_event_loop()
1614

1715
if __name__ == "__main__":
1816
try:
1917
# Greet user
2018
print("Hi... I'm an echobot. Whatever you say I'll echo back.")
2119

22-
loop.run_until_complete(adapter.process_activity(bot.on_turn))
20+
LOOP.run_until_complete(ADAPTER.process_activity(BOT.on_turn))
2321
except KeyboardInterrupt:
2422
pass
2523
finally:
26-
loop.stop()
27-
loop.close()
24+
LOOP.stop()
25+
LOOP.close()

samples/02.echo-bot/app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import asyncio
55
import sys
66
from datetime import datetime
7-
from types import MethodType
87

98
from flask import Flask, request, Response
109
from botbuilder.core import BotFrameworkAdapterSettings, TurnContext, BotFrameworkAdapter
@@ -24,7 +23,7 @@
2423

2524

2625
# Catch-all for errors.
27-
async def on_error(self, context: TurnContext, error: Exception):
26+
async def on_error(context: TurnContext, error: Exception):
2827
# This check writes out errors to console log .vs. app insights.
2928
# NOTE: In production environment, you should consider logging this to Azure
3029
# application insights.
@@ -47,7 +46,7 @@ async def on_error(self, context: TurnContext, error: Exception):
4746
# Send a trace activity, which will be displayed in Bot Framework Emulator
4847
await context.send_activity(trace_activity)
4948

50-
ADAPTER.on_turn_error = MethodType(on_error, ADAPTER)
49+
ADAPTER.on_turn_error = on_error
5150

5251
# Create the Bot
5352
BOT = EchoBot()

samples/03.welcome-user/app.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import asyncio
55
import sys
66
from datetime import datetime
7-
from types import MethodType
87

98
from flask import Flask, request, Response
109
from botbuilder.core import (
@@ -30,30 +29,33 @@
3029

3130

3231
# Catch-all for errors.
33-
async def on_error(self, context: TurnContext, error: Exception):
32+
async def on_error(context: TurnContext, error: Exception):
3433
# This check writes out errors to console log .vs. app insights.
3534
# NOTE: In production environment, you should consider logging this to Azure
3635
# application insights.
3736
print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr)
3837

3938
# Send a message to the user
4039
await context.send_activity("The bot encountered an error or bug.")
41-
await context.send_activity("To continue to run this bot, please fix the bot source code.")
40+
await context.send_activity(
41+
"To continue to run this bot, please fix the bot source code."
42+
)
4243
# Send a trace activity if we're talking to the Bot Framework Emulator
43-
if context.activity.channel_id == 'emulator':
44+
if context.activity.channel_id == "emulator":
4445
# Create a trace activity that contains the error object
4546
trace_activity = Activity(
4647
label="TurnError",
4748
name="on_turn_error Trace",
4849
timestamp=datetime.utcnow(),
4950
type=ActivityTypes.trace,
5051
value=f"{error}",
51-
value_type="https://www.botframework.com/schemas/error"
52+
value_type="https://www.botframework.com/schemas/error",
5253
)
5354
# Send a trace activity, which will be displayed in Bot Framework Emulator
5455
await context.send_activity(trace_activity)
5556

56-
ADAPTER.on_turn_error = MethodType(on_error, ADAPTER)
57+
58+
ADAPTER.on_turn_error = on_error
5759

5860
# Create MemoryStorage, UserState
5961
MEMORY = MemoryStorage()
Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
from botbuilder.core import ActivityHandler, TurnContext, UserState, CardFactory, MessageFactory
5-
from botbuilder.schema import ChannelAccount, HeroCard, CardImage, CardAction, ActionTypes
4+
from botbuilder.core import (
5+
ActivityHandler,
6+
TurnContext,
7+
UserState,
8+
CardFactory,
9+
MessageFactory,
10+
)
11+
from botbuilder.schema import (
12+
ChannelAccount,
13+
HeroCard,
14+
CardImage,
15+
CardAction,
16+
ActionTypes,
17+
)
618

719
from data_models import WelcomeUserState
820

@@ -18,76 +30,76 @@ def __init__(self, user_state: UserState):
1830

1931
self.user_state_accessor = self.user_state.create_property("WelcomeUserState")
2032

21-
self.WELCOME_MESSAGE = """This is a simple Welcome Bot sample. This bot will introduce you
22-
to welcoming and greeting users. You can say 'intro' to see the
23-
introduction card. If you are running this bot in the Bot Framework
24-
Emulator, press the 'Restart Conversation' button to simulate user joining
33+
self.WELCOME_MESSAGE = """This is a simple Welcome Bot sample. This bot will introduce you
34+
to welcoming and greeting users. You can say 'intro' to see the
35+
introduction card. If you are running this bot in the Bot Framework
36+
Emulator, press the 'Restart Conversation' button to simulate user joining
2537
a bot or a channel"""
26-
38+
2739
async def on_turn(self, turn_context: TurnContext):
2840
await super().on_turn(turn_context)
2941

3042
# save changes to WelcomeUserState after each turn
3143
await self.user_state.save_changes(turn_context)
3244

33-
"""
34-
Greet when users are added to the conversation.
35-
Note that all channels do not send the conversation update activity.
36-
If you find that this bot works in the emulator, but does not in
37-
another channel the reason is most likely that the channel does not
38-
send this activity.
39-
"""
40-
4145
async def on_members_added_activity(
4246
self, members_added: [ChannelAccount], turn_context: TurnContext
4347
):
48+
"""
49+
Greet when users are added to the conversation.
50+
Note that all channels do not send the conversation update activity.
51+
If you find that this bot works in the emulator, but does not in
52+
another channel the reason is most likely that the channel does not
53+
send this activity.
54+
"""
4455
for member in members_added:
4556
if member.id != turn_context.activity.recipient.id:
4657
await turn_context.send_activity(
4758
f"Hi there { member.name }. " + self.WELCOME_MESSAGE
4859
)
4960

50-
await turn_context.send_activity("""You are seeing this message because the bot received at least one
51-
'ConversationUpdate' event, indicating you (and possibly others)
52-
joined the conversation. If you are using the emulator, pressing
53-
the 'Start Over' button to trigger this event again. The specifics
54-
of the 'ConversationUpdate' event depends on the channel. You can
61+
await turn_context.send_activity(
62+
"""You are seeing this message because the bot received at least one
63+
'ConversationUpdate' event, indicating you (and possibly others)
64+
joined the conversation. If you are using the emulator, pressing
65+
the 'Start Over' button to trigger this event again. The specifics
66+
of the 'ConversationUpdate' event depends on the channel. You can
5567
read more information at: https://aka.ms/about-botframework-welcome-user"""
5668
)
5769

58-
await turn_context.send_activity("""It is a good pattern to use this event to send general greeting
59-
to user, explaining what your bot can do. In this example, the bot
70+
await turn_context.send_activity(
71+
"""It is a good pattern to use this event to send general greeting
72+
to user, explaining what your bot can do. In this example, the bot
6073
handles 'hello', 'hi', 'help' and 'intro'. Try it now, type 'hi'"""
6174
)
6275

63-
"""
64-
Respond to messages sent from the user.
65-
"""
66-
6776
async def on_message_activity(self, turn_context: TurnContext):
77+
"""
78+
Respond to messages sent from the user.
79+
"""
6880
# Get the state properties from the turn context.
69-
welcome_user_state = await self.user_state_accessor.get(turn_context, WelcomeUserState)
81+
welcome_user_state = await self.user_state_accessor.get(
82+
turn_context, WelcomeUserState
83+
)
7084

7185
if not welcome_user_state.did_welcome_user:
7286
welcome_user_state.did_welcome_user = True
7387

7488
await turn_context.send_activity(
7589
"You are seeing this message because this was your first message ever to this bot."
76-
)
90+
)
7791

7892
name = turn_context.activity.from_property.name
7993
await turn_context.send_activity(
80-
f"It is a good practice to welcome the user and provide personal greeting. For example: Welcome { name }"
94+
f"It is a good practice to welcome the user and provide personal greeting. For example: Welcome {name}"
8195
)
82-
96+
8397
else:
8498
# This example hardcodes specific utterances. You should use LUIS or QnA for more advance language
8599
# understanding.
86100
text = turn_context.activity.text.lower()
87101
if text in ("hello", "hi"):
88-
await turn_context.send_activity(
89-
f"You said { text }"
90-
)
102+
await turn_context.send_activity(f"You said { text }")
91103
elif text in ("intro", "help"):
92104
await self.__send_intro_card(turn_context)
93105
else:
@@ -97,37 +109,35 @@ async def __send_intro_card(self, turn_context: TurnContext):
97109
card = HeroCard(
98110
title="Welcome to Bot Framework!",
99111
text="Welcome to Welcome Users bot sample! This Introduction card "
100-
"is a great way to introduce your Bot to the user and suggest "
101-
"some things to get them started. We use this opportunity to "
102-
"recommend a few next steps for learning more creating and deploying bots.",
103-
images=[
104-
CardImage(
105-
url="https://aka.ms/bf-welcome-card-image"
106-
)
107-
],
112+
"is a great way to introduce your Bot to the user and suggest "
113+
"some things to get them started. We use this opportunity to "
114+
"recommend a few next steps for learning more creating and deploying bots.",
115+
images=[CardImage(url="https://aka.ms/bf-welcome-card-image")],
108116
buttons=[
109117
CardAction(
110118
type=ActionTypes.open_url,
111119
title="Get an overview",
112120
text="Get an overview",
113121
display_text="Get an overview",
114-
value="https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0"
122+
value="https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0",
115123
),
116124
CardAction(
117125
type=ActionTypes.open_url,
118126
title="Ask a question",
119127
text="Ask a question",
120128
display_text="Ask a question",
121-
value="https://stackoverflow.com/questions/tagged/botframework"
129+
value="https://stackoverflow.com/questions/tagged/botframework",
122130
),
123131
CardAction(
124132
type=ActionTypes.open_url,
125133
title="Learn how to deploy",
126134
text="Learn how to deploy",
127135
display_text="Learn how to deploy",
128-
value="https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-deploy-azure?view=azure-bot-service-4.0"
129-
)
130-
]
136+
value="https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-deploy-azure?view=azure-bot-service-4.0",
137+
),
138+
],
131139
)
132140

133-
return await turn_context.send_activity(MessageFactory.attachment(CardFactory.hero_card(card)))
141+
return await turn_context.send_activity(
142+
MessageFactory.attachment(CardFactory.hero_card(card))
143+
)

samples/05.multi-turn-prompt/app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ async def on_error(context: TurnContext, error: Exception):
3939

4040
# Send a message to the user
4141
await context.send_activity("The bot encountered an error or bug.")
42-
await context.send_activity("To continue to run this bot, please fix the bot source code.")
42+
await context.send_activity(
43+
"To continue to run this bot, please fix the bot source code."
44+
)
4345
# Send a trace activity if we're talking to the Bot Framework Emulator
44-
if context.activity.channel_id == 'emulator':
46+
if context.activity.channel_id == "emulator":
4547
# Create a trace activity that contains the error object
4648
trace_activity = Activity(
4749
label="TurnError",
4850
name="on_turn_error Trace",
4951
timestamp=datetime.utcnow(),
5052
type=ActivityTypes.trace,
5153
value=f"{error}",
52-
value_type="https://www.botframework.com/schemas/error"
54+
value_type="https://www.botframework.com/schemas/error",
5355
)
5456

5557
# Send a trace activity, which will be displayed in Bot Framework Emulator
@@ -58,6 +60,7 @@ async def on_error(context: TurnContext, error: Exception):
5860
# Clear out state
5961
await CONVERSATION_STATE.delete(context)
6062

63+
6164
# Set the error handler on the Adapter.
6265
# In this case, we want an unbound method, so MethodType is not needed.
6366
ADAPTER.on_turn_error = on_error

samples/05.multi-turn-prompt/bots/dialog_bot.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
from botbuilder.dialogs import Dialog
66
from helpers.dialog_helper import DialogHelper
77

8-
"""
9-
This Bot implementation can run any type of Dialog. The use of type parameterization is to allows multiple
10-
different bots to be run at different endpoints within the same project. This can be achieved by defining distinct
11-
Controller types each with dependency on distinct Bot types. The ConversationState is used by the Dialog system. The
12-
UserState isn't, however, it might have been used in a Dialog implementation, and the requirement is that all
13-
BotState objects are saved at the end of a turn.
14-
"""
15-
168

179
class DialogBot(ActivityHandler):
10+
"""
11+
This Bot implementation can run any type of Dialog. The use of type parameterization is to allows multiple
12+
different bots to be run at different endpoints within the same project. This can be achieved by defining distinct
13+
Controller types each with dependency on distinct Bot types. The ConversationState is used by the Dialog system. The
14+
UserState isn't, however, it might have been used in a Dialog implementation, and the requirement is that all
15+
BotState objects are saved at the end of a turn.
16+
"""
17+
1818
def __init__(
19-
self,
20-
conversation_state: ConversationState,
19+
self,
20+
conversation_state: ConversationState,
2121
user_state: UserState,
22-
dialog: Dialog
22+
dialog: Dialog,
2323
):
2424
if conversation_state is None:
2525
raise TypeError(

0 commit comments

Comments
 (0)
0