10000 Fixing python313 deprecation warnings (#2159) · ultrarslanoglu/botbuilder-python@bb1561e · GitHub
[go: up one dir, main page]

Skip to content

Commit bb1561e

Browse files
authored
Fixing python313 deprecation warnings (microsoft#2159)
* Fixing DeprecationWarnings in Python 3.13.0rc1 * Fix black issues * Fixing pylint issue
1 parent f3d50f8 commit bb1561e

File tree

13 files changed

+37
-28
lines changed

13 files changed

+37
-28
lines changed

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

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

4-
from datetime import datetime
4+
from datetime import datetime, timezone
55

66
from botbuilder.schema import (
77
Activity,
@@ -51,7 +51,7 @@ def create_trace(
5151

5252
reply = Activity(
5353
type=ActivityTypes.trace,
54-
timestamp=datetime.utcnow(),
54+
timestamp=datetime.now(timezone.utc),
5555
from_property=from_property,
5656
recipient=ChannelAccount(
5757
id=turn_activity.from_property.id, name=turn_activity.from_property.name

libraries/botbuilder-ai/tests/qna/test_qna.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,6 @@ async def test_trace_test(self):
347347
self._knowledge_base_id, trace_activity.value.knowledge_base_id
348348
)
349349

350-
return result
351-
352350
async def test_returns_answer_with_timeout(self):
353351
question: str = "how do I clean the stove?"
354352
options = QnAMakerOptions(timeout=999999)
@@ -823,7 +821,7 @@ async def test_call_train(self):
823821
QnAMaker, "call_train", return_value=None
824822
) as mocked_call_train:
825823
qna = QnAMaker(QnaApplicationTest.tests_endpoint)
826-
qna.call_train(feedback_records)
824+
await qna.call_train(feedback_records)
827825

828826
mocked_call_train.assert_called_once_with(feedback_records)
829827

libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/processor/telemetry_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import base64
44
import json
55
from abc import ABC, abstractmethod
6-
from _sha256 import sha256
6+
from hashlib import sha256
77

88

99
class TelemetryProcessor(ABC):

libraries/botbuilder-applicationinsights/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
]
1313
TESTS_REQUIRES = [
1414
"aiounittest==1.3.0",
15-
"django==3.2.24", # For samples
15+
"django==4.2.15", # For samples
1616
"djangorestframework==3.14.0", # For samples
1717
"flask==2.2.5", # For samples
1818
]

libraries/botbuilder-core/botbuilder/core/adapters/test_adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import asyncio
99
import inspect
1010
import uuid
11-
from datetime import datetime
11+
from datetime import datetime, timezone
1212
from uuid import uuid4
1313
from typing import Awaitable, Coroutine, Dict, List, Callable, Union
1414
from copy import copy
@@ -155,7 +155,7 @@ async def process_activity(
155155
finally:
156156
self._conversation_lock.release()
157157

158-
activity.timestamp = activity.timestamp or datetime.utcnow()
158+
activity.timestamp = activity.timestamp or datetime.now(timezone.utc)
159159
await self.run_pipeline(self.create_turn_context(activity), logic)
160160

161161
async def send_activities(

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

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

4-
from datetime import datetime
4+
from datetime import datetime, timezone
55
from typing import Dict, Union
66

77
from botbuilder.core import BotState
@@ -11,7 +11,7 @@
1111
def make_command_activity(command: str) -> Activity:
1212
return Activity(
1313
type=ActivityTypes.trace,
14-
timestamp=datetime.utcnow(),
14+
timestamp=datetime.now(timezone.utc),
1515
name="Command",
1616
label="Command",
1717
value=command,
@@ -22,7 +22,7 @@ def make_command_activity(command: str) -> Activity:
2222
def from_activity(activity: Activity, name: str, label: str) -> Activity:
2323
return Activity(
2424
type=ActivityTypes.trace,
25-
timestamp=datetime.utcnow(),
25+
timestamp=datetime.now(timezone.utc),
2626
name=name,
2727
label=label,
2828
value=activity,
@@ -33,7 +33,7 @@ def from_activity(activity: Activity, name: str, label: str) -> Activity:
3333
def from_state(bot_state: Union[BotState, Dict]) -> Activity:
3434
return Activity(
3535
type=ActivityTypes.trace,
36-
timestamp=datetime.utcnow(),
36+
timestamp=datetime.now(timezone.utc),
3737
name="Bot State",
3838
label="BotState",
3939
value=bot_state,

libraries/botbuilder-core/botbuilder/core/transcript_logger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the MIT License.
33
"""Logs incoming and outgoing activities to a TranscriptStore.."""
44

5-
import datetime
5+
from datetime import datetime, timezone
66
import copy
77
import random
88
import string
@@ -86,11 +86,11 @@ async def send_activities_handler(
8686
prefix = "g_" + "".join(
8787
random.choice(alphanumeric) for i in range(5)
8888
)
89-
epoch = datetime.datetime.utcfromtimestamp(0)
89+
epoch = datetime.fromtimestamp(0, timezone.utc)
9090
if cloned_activity.timestamp:
9191
reference = cloned_activity.timestamp
9292
else:
93-
reference = datetime.datetime.today()
93+
reference = datetime.now(timezone.utc)
9494
delta = (reference - epoch).total_seconds() * 1000
9595
cloned_activity.id = f"{prefix}{delta}"
9696
await self.log_activity(transcript, cloned_activity)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import re
55
from copy import copy, deepcopy
6-
from datetime import datetime
6+
from datetime import datetime, timezone
77
from typing import List, Callable, Union, Dict
88
from botframework.connector import Channels
99
from botbuilder.schema import (
@@ -308,7 +308,7 @@ async def send_trace_activity(
308308
) -> ResourceResponse:
309309
trace_activity = Activity(
310310
type=ActivityTypes.trace,
311-
timestamp=datetime.utcnow(),
311+
timestamp=datetime.now(timezone.utc),
312312
name=name,
313313
value=value,
314314
value_type=value_type,

libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,11 @@ async def _recognize_token(
420420
)
421421

422422
elif OAuthPrompt._is_teams_verification_invoke(context):
423-
code = context.activity.value["state"]
423+
code = (
424+
context.activity.value.get("state", None)
425+
if context.activity.value
426+
else None
427+
)
424428
try:
425429
token = await _UserTokenAccess.get_user_token(
426430
context, self._settings, code

libraries/botbuilder-schema/botbuilder/schema/_models_py3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import List
55

66
from botbuilder.schema._connector_client_enums import ActivityTypes
7-
from datetime import datetime
7+
from datetime import datetime, timezone
88
from enum import Enum
99
from msrest.serialization import Model
1010
from msrest.exceptions import HttpOperationError
@@ -630,7 +630,7 @@ def create_reply(self, text: str = None, locale: str = None):
630630
"""
631631
return Activity(
632632
type=ActivityTypes.message,
633-
timestamp=datetime.utcnow(),
633+
timestamp=datetime.now(timezone.utc),
634634
from_property=ChannelAccount(
635635
id=self.recipient.id if self.recipient else None,
636636
name=self.recipient.name if self.recipient else None,
@@ -677,7 +677,7 @@ def create_trace(
677677

678678
return Activity(
679679
type=ActivityTypes.trace,
680-
timestamp=datetime.utcnow(),
680+
timestamp=datetime.now(timezone.utc),
681681
from_property=ChannelAccount(
682682
id=self.recipient.id if self.recipient else None,
683683
name=self.recipient.name if self.recipient else None,

0 commit comments

Comments
 (0)
0