Skip to content

Fixing python313 deprecation warnings #2159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/botbuilder-ai/botbuilder/ai/luis/activity_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from datetime import datetime
from datetime import datetime, timezone

from botbuilder.schema import (
Activity,
Expand Down Expand Up @@ -51,7 +51,7 @@ def create_trace(

reply = Activity(
type=ActivityTypes.trace,
timestamp=datetime.utcnow(),
timestamp=datetime.now(timezone.utc),
from_property=from_property,
recipient=ChannelAccount(
id=turn_activity.from_property.id, name=turn_activity.from_property.name
Expand Down
4 changes: 1 addition & 3 deletions libraries/botbuilder-ai/tests/qna/test_qna.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ async def test_trace_test(self):
self._knowledge_base_id, trace_activity.value.knowledge_base_id
)

return result

async def test_returns_answer_with_timeout(self):
question: str = "how do I clean the stove?"
options = QnAMakerOptions(timeout=999999)
Expand Down Expand Up @@ -823,7 +821,7 @@ async def test_call_train(self):
QnAMaker, "call_train", return_value=None
) as mocked_call_train:
qna = QnAMaker(QnaApplicationTest.tests_endpoint)
qna.call_train(feedback_records)
await qna.call_train(feedback_records)

mocked_call_train.assert_called_once_with(feedback_records)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import base64
import json
from abc import ABC, abstractmethod
from _sha256 import sha256
from hashlib import sha256


class TelemetryProcessor(ABC):
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-applicationinsights/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
]
TESTS_REQUIRES = [
"aiounittest==1.3.0",
"django==3.2.24", # For samples
"django==4.2.15", # For samples
"djangorestframework==3.14.0", # For samples
"flask==2.2.5", # For samples
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import asyncio
import inspect
import uuid
from datetime import datetime
from datetime import datetime, timezone
from uuid import uuid4
from typing import Awaitable, Coroutine, Dict, List, Callable, Union
from copy import copy
Expand Down Expand Up @@ -155,7 +155,7 @@ async def process_activity(
finally:
self._conversation_lock.release()

activity.timestamp = activity.timestamp or datetime.utcnow()
activity.timestamp = activity.timestamp or datetime.now(timezone.utc)
await self.run_pipeline(self.create_turn_context(activity), logic)

async def send_activities(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from datetime import datetime
from datetime import datetime, timezone
from typing import Dict, Union

from botbuilder.core import BotState
Expand All @@ -11,7 +11,7 @@
def make_command_activity(command: str) -> Activity:
return Activity(
type=ActivityTypes.trace,
timestamp=datetime.utcnow(),
timestamp=datetime.now(timezone.utc),
name="Command",
label="Command",
value=command,
Expand All @@ -22,7 +22,7 @@ def make_command_activity(command: str) -> Activity:
def from_activity(activity: Activity, name: str, label: str) -> Activity:
return Activity(
type=ActivityTypes.trace,
timestamp=datetime.utcnow(),
timestamp=datetime.now(timezone.utc),
name=name,
label=label,
value=activity,
Expand All @@ -33,7 +33,7 @@ def from_activity(activity: Activity, name: str, label: str) -> Activity:
def from_state(bot_state: Union[BotState, Dict]) -> Activity:
return Activity(
type=ActivityTypes.trace,
timestamp=datetime.utcnow(),
timestamp=datetime.now(timezone.utc),
name="Bot State",
label="BotState",
value=bot_state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.
"""Logs incoming and outgoing activities to a TranscriptStore.."""

import datetime
from datetime import datetime, timezone
import copy
import random
import string
Expand Down Expand Up @@ -86,11 +86,11 @@ async def send_activities_handler(
prefix = "g_" + "".join(
random.choice(alphanumeric) for i in range(5)
)
epoch = datetime.datetime.utcfromtimestamp(0)
epoch = datetime.fromtimestamp(0, timezone.utc)
if cloned_activity.timestamp:
reference = cloned_activity.timestamp
else:
reference = datetime.datetime.today()
reference = datetime.now(timezone.utc)
delta = (reference - epoch).total_seconds() * 1000
cloned_activity.id = f"{prefix}{delta}"
await self.log_activity(transcript, cloned_activity)
Expand Down
4 changes: 2 additions & 2 deletions libraries/botbuilder-core/botbuilder/core/turn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import re
from copy import copy, deepcopy
from datetime import datetime
from datetime import datetime, timezone
from typing import List, Callable, Union, Dict
from botframework.connector import Channels
from botbuilder.schema import (
Expand Down Expand Up @@ -308,7 +308,7 @@ async def send_trace_activity(
) -> ResourceResponse:
trace_activity = Activity(
type=ActivityTypes.trace,
timestamp=datetime.utcnow(),
timestamp=datetime.now(timezone.utc),
name=name,
value=value,
value_type=value_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ async def _recognize_token(
)

elif OAuthPrompt._is_teams_verification_invoke(context):
code = context.activity.value["state"]
code = (
context.activity.value.get("state", None)
if context.activity.value
else None
)
try:
token = await _UserTokenAccess.get_user_token(
context, self._settings, code
Expand Down
6 changes: 3 additions & 3 deletions libraries/botbuilder-schema/botbuilder/schema/_models_py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List

from botbuilder.schema._connector_client_enums import ActivityTypes
from datetime import datetime
from datetime import datetime, timezone
from enum import Enum
from msrest.serialization import Model
from msrest.exceptions import HttpOperationError
Expand Down Expand Up @@ -630,7 +630,7 @@ def create_reply(self, text: str = None, locale: str = None):
"""
return Activity(
type=ActivityTypes.message,
timestamp=datetime.utcnow(),
timestamp=datetime.now(timezone.utc),
from_property=ChannelAccount(
id=self.recipient.id if self.recipient else None,
name=self.recipient.name if self.recipient else None,
Expand Down Expand Up @@ -677,7 +677,7 @@ def create_trace(

return Activity(
type=ActivityTypes.trace,
timestamp=datetime.utcnow(),
timestamp=datetime.now(timezone.utc),
from_property=ChannelAccount(
id=self.recipient.id if self.recipient else None,
name=self.recipient.name if self.recipient else None,
Expand Down
4 changes: 1 addition & 3 deletions libraries/botframework-connector/azure_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,7 @@ def write_record(self, bdist_dir, distinfo_dir):
for azure_sub_package in folder_with_init:
init_file = os.path.join(bdist_dir, azure_sub_package, "__init__.py")
if os.path.isfile(init_file):
logger.info(
"manually remove {} while building the wheel".format(init_file)
)
logger.info("manually remove %s while building the wheel", init_file)
os.remove(init_file)
else:
raise ValueError(
Expand Down
5 changes: 3 additions & 2 deletions libraries/botframework-connector/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest-cov>=2.6.0
pytest~=7.3.1
pyyaml==6.0.1
pytest-asyncio==0.15.1
ddt==1.2.1
pytest-asyncio==0.23.8
ddt==1.2.1
setuptools==72.1.0
10 changes: 9 additions & 1 deletion libraries/botframework-connector/tests/test_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ def read_base64(path_to_file):
return encoded_string


LOOP = asyncio.get_event_loop()
# Ensure there's an event loop and get the auth token
# LOOP = asyncio.get_event_loop()
try:
LOOP = asyncio.get_running_loop()
except RuntimeError:
LOOP = asyncio.new_event_loop()
asyncio.set_event_loop(LOOP)

# Run the async function to get the auth token
AUTH_TOKEN = LOOP.run_until_complete(get_auth_token())


Expand Down
Loading