8000 Python 3.11 Compatibility (#2022) · dldinternet/botbuilder-python@d475640 · GitHub
[go: up one dir, main page]

Skip to content

Commit d475640

Browse files
authored
Python 3.11 Compatibility (microsoft#2022)
* make updates to run tests with 3.11 * run black * Update botbuilder-python-ci.yml * update azure devtools * remove `azure-devtools` due to it being archived * remove deprecation warning * lint ignore test files * ignore tests folder entirely * Update .pylintrc * Update .pylintrc * Update .pylintrc * only fail on errors * Update botbuilder-python-ci.yml * fixes for lint * test update pylint version * remove python 3.11 matrix (to be added in separate PR)
1 parent 40a4f60 commit d475640

File tree

76 files changed

+38
-122
lines changed

Some content is hidden

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

76 files changed

+38
-122
lines changed

.pylintrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extension-pkg-whitelist=
77

88
# Add files or directories to the blacklist. They should be base names, not
99
# paths.
10-
ignore=CVS,build,botbuilder-schema,samples,django_tests,Generator,operations,operations_async,schema
10+
ignore=CVS,build,botbuilder-schema,samples,django_tests,Generator,operations,operations_async,schema,tests
1111

1212
# Add files or directories matching the regex patterns to the blacklist. The
1313
# regex matches against base names, not paths.
@@ -160,7 +160,8 @@ disable=print-statement,
160160
no-name-in-module,
161161
too-many-branches,
162162
too-many-ancestors,
163-
too-many-nested-blocks
163+
too-many-nested-blocks,
164+
attribute-defined-outside-init
164165

165166
# Enable the message, report, category or checker with the given id(s). You can
166167
# either give multiple identifier separated by comma (,) or put this option

libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ async def _recognize_internal(
256256
LuisPredictionOptions, LuisRecognizerOptionsV2, LuisRecognizerOptionsV3
257257
] = None,
258258
) -> RecognizerResult:
259-
260259
BotAssert.context_not_none(turn_context)
261260

262261
if turn_context.activity.type != ActivityTypes.message:
@@ -277,7 +276,6 @@ async def _recognize_internal(
277276
text=utterance, intents={"": IntentScore(score=1.0)}, entities={}
278277
)
279278
else:
280-
281279
luis_recognizer = self._build_recognizer(options)
282280
recognizer_result = await luis_recognizer.recognizer_internal(turn_context)
283281

libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919

2020
class LuisRecognizerV2(LuisRecognizerInternal):
21-
2221
# The value type for a LUIS trace activity.
2322
luis_trace_type: str = "https://www.luis.ai/schemas/trace"
2423

@@ -43,7 +42,6 @@ def __init__(
4342
self._application = luis_application
4443

4544
async def recognizer_internal(self, turn_context: TurnContext):
46-
4745
utterance: str = (
4846
turn_context.activity.text if turn_context.activity is not None else None
4947
)

libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v3.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ async def recognizer_internal(self, turn_context: TurnContext):
102102
return recognizer_result
103103

104104
def _build_url(self):
105-
106105
base_uri = (
107106
self._application.endpoint or "https://westus.api.cognitive.microsoft.com"
108107
)
@@ -172,7 +171,6 @@ def _extract_entities_and_metadata(self, luis_result):
172171
return self._map_properties(entities, False)
173172

174173
def _map_properties(self, source, in_instance):
175-
176174
if isinstance(source, (int, float, bool, str)):
177175
return source
178176

libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ def _validate_options(self, options: QnAMakerOptions):
254254
def _has_matched_answer_in_kb(self, query_results: [QueryResult]) -> bool:
255255
if query_results:
256256
if query_results[0].id != -1:
257-
258257
return True
259258

260259
return False

libraries/botbuilder-applicationinsights/tests/test_telemetry_waterfall.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ async def step2(step) -> DialogTurnResult:
6565

6666
# Initialize TestAdapter
6767
async def exec_test(turn_context: TurnContext) -> None:
68-
6968
dialog_context = await dialogs.create_context(turn_context)
7069
results = await dialog_context.continue_dialog()
7170
if results.status == DialogTurnStatus.Empty:
@@ -119,7 +118,6 @@ async def step2(step) -> DialogTurnResult:
119118

120119
# Initialize TestAdapter
121120
async def exec_test(turn_context: TurnContext) -> None:
122-
123121
dialog_context = await dialogs.create_context(turn_context)
124122
await dialog_context.continue_dialog()
125123
if not turn_context.responded:

libraries/botbuilder-azure/botbuilder/azure/blob_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def write(self, changes: Dict[str, object]):
143143

144144
await self._initialize()
145145

146-
for (name, item) in changes.items():
146+
for name, item in changes.items():
147147
blob_reference = self.__container_client.get_blob_client(name)
148148

149149
e_tag = None

libraries/botbuilder-azure/botbuilder/azure/cosmosdb_partitioned_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ async def write(self, changes: Dict[str, object]):
146146

147147
await self.initialize()
148148

149-
for (key, change) in changes.items():
149+
for key, change in changes.items():
150150
e_tag = None
151151
if isinstance(change, dict):
152152
e_tag = change.get("e_tag", None)

libraries/botbuilder-azure/botbuilder/azure/cosmosdb_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async def write(self, changes: Dict[str, object]):
178178
if not self.__container_exists:
179179
self.__create_db_and_container()
180180
# iterate over the changes
181-
for (key, change) in changes.items():
181+
for key, change in changes.items():
182182
# store the e_tag
183183
e_tag = None
184184
if isinstance(change, dict):

libraries/botbuilder-core/botbuilder/core/bot_framework_adapter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,6 @@ async def get_user_token(
910910
magic_code: str = None,
911911
oauth_app_credentials: AppCredentials = None, # pylint: disable=unused-argument
912912
) -> TokenResponse:
913-
914913
"""
915914
Attempts to retrieve the token for a user that's in a login flow.
916915

libraries/botbuilder-core/botbuilder/core/bot_state.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class CachedBotState:
1818
"""
1919

2020
def __init__(self, state: Dict[str, object] = None):
21-
2221
self.state = state if state is not None else {}
2322
self.hash = self.compute_hash(state)
2423

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
from asyncio import wait
54
from typing import List
65
from .bot_state import BotState
76
from .turn_context import TurnContext
@@ -19,14 +18,9 @@ def add(self, bot_state: BotState) -> "BotStateSet":
1918
return self
2019

2120
async def load_all(self, turn_context: TurnContext, force: bool = False):
22-
await wait(
23-
[bot_state.load(turn_context, force) for bot_state in self.bot_states]
24-
)
21+
for bot_state in self.bot_states:
22+
await bot_state.load(turn_context, force)
2523

2624
async def save_all_changes(self, turn_context: TurnContext, force: bool = False):
27-
await wait(
28-
[
29-
bot_state.save_changes(turn_context, force)
30-
for bot_state in self.bot_states
31-
]
32-
)
25+
for bot_state in self.bot_states:
26+
await bot_state.save_changes(turn_context, force)

libraries/botbuilder-core/botbuilder/core/inspection/inspection_middleware.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def __init__( # pylint: disable=super-init-not-called
2929
conversation_state: ConversationState = None,
3030
credentials: MicrosoftAppCredentials = None,
3131
):
32-
3332
self.inspection_state = inspection_state
3433
self.inspection_state_accessor = inspection_state.create_property(
3534
"InspectionSessionByStatus"
@@ -43,13 +42,11 @@ def __init__( # pylint: disable=super-init-not-called
4342

4443
async def process_command(self, context: TurnContext) -> Any:
4544
if context.activity.type == ActivityTypes.message and context.activity.text:
46-
4745
original_text = context.activity.text
4846
TurnContext.remove_recipient_mention(context.activity)
4947

5048
command = context.activity.text.strip().split(" ")
5149
if len(command) > 1 and command[0] == InspectionMiddleware._COMMAND:
52-
5350
if len(command) == 2 and command[1] == "open":
5451
await self._process_open_command(context)
5552
return True

libraries/botbuilder-core/botbuilder/core/memory_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def write(self, changes: Dict[str, StoreItem]):
4040
return
4141
try:
4242
# iterate over the changes
43-
for (key, change) in changes.items():
43+
for key, change in changes.items():
4444
new_value = deepcopy(change)
4545
old_state_etag = None
4646

libraries/botbuilder-core/botbuilder/core/middleware_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def use(self, *middleware: Middleware):
4545
:param middleware :
4646
:return:
4747
"""
48-
for (idx, mid) in enumerate(middleware):
48+
for idx, mid in enumerate(middleware):
4949
if hasattr(mid, "on_turn") and callable(mid.on_turn):
5050
self._middleware.append(mid)
5151
return self

libraries/botbuilder-core/botbuilder/core/skills/skill_handler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121

2222
class SkillHandler(ChannelServiceHandler):
23-
2423
SKILL_CONVERSATION_REFERENCE_KEY = (
2524
"botbuilder.core.skills.SkillConversationReference"
2625
)

libraries/botbuilder-core/botbuilder/core/streaming/bot_framework_http_adapter_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def can_process_outgoing_activity(self, activity: Activity) -> bool:
8989
return not activity.service_url.startswith("https")
9090

9191
async def process_outgoing_activity(
92-
self, turn_context: TurnContext, activity: Activity
92+
self, _turn_context: TurnContext, activity: Activity
9393
) -> ResourceResponse:
9494
if not activity:
9595
raise TypeError(

libraries/botbuilder-core/botbuilder/core/teams/teams_info.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ async def get_paged_team_members(
141141
async def get_paged_members(
142142
turn_context: TurnContext, continuation_token: str = None, page_size: int = None
143143
) -> List[TeamsPagedMembersResult]:
144-
145144
team_id = TeamsInfo.get_team_id(turn_context)
146145
if not team_id:
147146
conversation_id = turn_context.activity.conversation.id

libraries/botbuilder-core/botbuilder/core/turn_context.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919

2020
class TurnContext:
21-
2221
# Same constant as in the BF Adapter, duplicating here to avoid circular dependency
2322
_INVOKE_RESPONSE_KEY = "BotFrameworkAdapter.InvokeResponse"
2423

libraries/botbuilder-core/tests/test_bot_framework_adapter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ async def aux_func_assert_tenant_id_copied(context):
319319
await adapter.process_activity(incoming, "", aux_func_assert_tenant_id_copied)
320320

321321
async def test_should_create_valid_conversation_for_msteams(self):
322-
323322
tenant_id = "testTenant"
324323

325324
reference = deepcopy(REFERENCE)

libraries/botbuilder-core/tests/test_inspection_middleware.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ async def exec_test(turn_context):
113113
y_prop = conversation_state.create_property("y")
114114

115115
async def exec_test2(turn_context):
116-
117116
await turn_context.send_activity(
118117
MessageFactory.text(f"echo: { turn_context.activity.text }")
119118
)
@@ -227,7 +226,6 @@ async def exec_test(turn_context):
227226
y_prop = conversation_state.create_property("y")
228227

229228
async def exec_test2(turn_context):
230-
231229
await turn_context.send_activity(
232230
MessageFactory.text(f"echo: {turn_context.activity.text}")
233231
)

libraries/botbuilder-core/tests/test_memory_transcript_store.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
ConversationReference,
2727
)
2828

29+
2930
# pylint: disable=line-too-long,missing-docstring
3031
class TestMemoryTranscriptStore(aiounittest.AsyncTestCase):
3132
# pylint: disable=unused-argument

libraries/botbuilder-core/tests/test_message_factory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def assert_attachments(activity: Activity, count: int, types: List[str] = None):
4949

5050

5151
class TestMessageFactory(aiounittest.AsyncTestCase):
52-
5352
suggested_actions = [
5453
CardAction(title="a", type=ActionTypes.im_back, value="a"),
5554
CardAction(title="b", type=ActionTypes.im_back, value="b"),

libraries/botbuilder-core/tests/test_middleware_set.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ async def request_handler(context_or_string):
5656
await middleware_set.receive_activity_internal("Bye", request_handler)
5757

5858
async def test_middleware_run_in_order(self):
59-
6059
called_first = False
6160
called_second = False
6261

libraries/botbuilder-core/tests/test_turn_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def send_activities(self, context, activities) -> List[ResourceResponse]:
3535
assert activities is not None
3636
assert isinstance(activities, list)
3737
assert activities
38-
for (idx, activity) in enumerate(activities): # pylint: disable=unused-variable
38+
for idx, activity in enumerate(activities): # pylint: disable=unused-variable
3939
assert isinstance(activity, Activity)
4040
assert activity.type == "message" or activity.type == ActivityTypes.trace
4141
responses.append(ResourceResponse(id="5678"))

libraries/botbuilder-dialogs/botbuilder/dialogs/choices/find.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def find_values(
101101
)
102102

103103
for entry in sorted_values:
104-
105104
# Find all matches for a value
106105
# - To match "last one" in "the last time I chose the last one" we need
107106
# to re-search the string starting from the end of the previous match.

libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_container.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ async def on_dialog_event(
6565

6666
# Trace unhandled "versionChanged" events.
6767
if not handled and dialog_event.name == DialogEvents.version_changed:
68-
6968
trace_message = (
7069
f"Unhandled dialog event: {dialog_event.name}. Active Dialog: "
7170
f"{dialog_context.active_dialog.id}"

libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_events.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class DialogEvents(str, Enum):
8-
98
begin_dialog = "beginDialog"
109
reprompt_dialog = "repromptDialog"
1110
cancel_dialog = "cancelDialog"

libraries/botbuilder-dialogs/botbuilder/dialogs/memory/dialog_state_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
# PathResolvers allow for shortcut behavior for mapping things like $foo -> dialog.foo.
3737
# </summary>
3838
class DialogStateManager:
39-
4039
SEPARATORS = [",", "["]
4140

4241
def __init__(

libraries/botbuilder-dialogs/botbuilder/dialogs/memory/path_resolvers/at_path_resolver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class AtPathResolver(AliasPathResolver):
8-
98
_DELIMITERS = [".", "["]
109

1110
def __init__(self):

libraries/botbuilder-dialogs/botbuilder/dialogs/memory/scopes/class_memory_scope.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _bind_to_dialog_context(obj, dialog_context: "DialogContext") -> object:
4141
if hasattr(prop_value, "try_get_value"):
4242
clone[prop] = prop_value.try_get_value(dialog_context.state)
4343
elif hasattr(prop_value, "__dict__") and not isinstance(
44-
prop_value, type
44+
prop_value, type(prop_value)
4545
):
4646
clone[prop] = ClassMemoryScope._bind_to_dialog_context(
4747
prop_value, dialog_context

libraries/botbuilder-dialogs/botbuilder/dialogs/waterfall_dialog.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def add_step(self, step):
4444
async def begin_dialog(
4545
self, dialog_context: DialogContext, options: object = None
4646
) -> DialogTurnResult:
47-
4847
if not dialog_context:
4948
raise TypeError("WaterfallDialog.begin_dialog(): dc cannot be None.")
5049

@@ -113,7 +112,6 @@ async def end_dialog( # pylint: disable=unused-argument
113112
self.telemetry_client.track_event("WaterfallCancel", properties)
114113
else:
115114
if reason is DialogReason.EndCalled:
116-
117115
instance_id = str(instance.state[self.PersistedInstanceId])
118116
properties = {"DialogId": self.id, "InstanceId": instance_id}
119117
self.telemetry_client.track_event("WaterfallComplete", properties)

libraries/botbuilder-dialogs/tests/test_confirm_prompt.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ async def exec_test(turn_context: TurnContext):
282282

283283
async def test_confirm_prompt_should_default_to_english_locale(self):
284284
async def exec_test(turn_context: TurnContext):
285-
286285
dialog_context = await dialogs.create_context(turn_context)
287286

288287
results: DialogTurnResult = await dialog_context.continue_dialog()

libraries/botbuilder-dialogs/tests/test_date_time_prompt.py

Lines changed: 0 ad B41A ditions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ async def exec_test(turn_context: TurnContext) -> None:
3232

3333
results = await dialog_context.continue_dialog()
3434
if results.status == DialogTurnStatus.Empty:
35-
3635
options = PromptOptions(prompt=MessageFactory.text(prompt_msg))
3736
await dialog_context.begin_dialog("DateTimePrompt", options)
3837
else:

libraries/botbuilder-dialogs/tests/test_number_prompt.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ async def test_number_uses_locale_specified_in_constructor(self):
180180
dialogs.add(number_prompt)
181181

182182
async def exec_test(turn_context: TurnContext) -> None:
183-
184183
dialog_context = await dialogs.create_context(turn_context)
185184
results = await dialog_context.continue_dialog()
186185

libraries/botbuilder-dialogs/tests/test_oauth_prompt.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ async def callback_handler(turn_context: TurnContext):
7676
async def inspector(
7777
activity: Activity, description: str = None
7878
): # pylint: disable=unused-argument
79-
8079
self.assertTrue(len(activity.attachments) == 1)
8180
self.assertTrue(
8281
activity.attachments[0].content_type
@@ -184,7 +183,6 @@ async def exec_test(turn_context: TurnContext):
184183

185184
results = await dialog_context.continue_dialog()
186185
if results.status == DialogTurnStatus.Empty:
187-
188186
# If magicCode is detected when prompting, this will end the dialog and return the token in tokenResult
189187
token_result = await dialog_context.prompt("prompt", PromptOptions())
190188
if isinstance(token_result.result, TokenResponse):

0 commit comments

Comments
 (0)
0