10000 Black and pylint compliant for all libraries (#275) · sherlock666/botbuilder-python@6cc2e00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6cc2e00

Browse files
authored
Black and pylint compliant for all libraries (microsoft#275)
* Black formatting after pylint changes, now enforcing black compliance in CI pipeline. * pylint changes
1 parent b0e444a commit 6cc2e00

Some content is hidden

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

42 files changed

+250
-155
lines changed

.pylintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ disable=print-statement,
156156
too-many-locals,
157157
too-many-function-args,
158158
too-many-return-statements,
159-
import-error
159+
import-error,
160+
no-name-in-module
160161

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

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
from azure.cognitiveservices.language.luis.runtime.models import LuisResult
99
from msrest.authentication import CognitiveServicesCredentials
1010

11-
from botbuilder.core import (
12-
BotAssert,
13-
IntentScore,
14-
RecognizerResult,
15-
TurnContext,
16-
)
11+
from botbuilder.core import BotAssert, IntentScore, RecognizerResult, TurnContext
1712
from botbuilder.schema import ActivityTypes
1813

1914
from . import LuisApplication, LuisPredictionOptions, LuisTelemetryConstants
@@ -158,7 +153,9 @@ def on_recognizer_result(
158153

159154
@staticmethod
160155
def _get_top_k_intent_score(
161-
intent_names: List[str], intents: Dict[str, IntentScore], index: int # pylint: disable=unused-argument
156+
intent_names: List[str],
157+
intents: Dict[str, IntentScore],
158+
index: int, # pylint: disable=unused-argument
162159
) -> Tuple[str, str]:
163160
intent_name = ""
164161
intent_score = "0.00"

libraries/botbuilder-ai/tests/luis/luis_application_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ def test_list_application_from_luis_endpoint(self) -> None:
4848
# Arrange
4949
# Note this is NOT a real LUIS application ID nor a real LUIS subscription-key
5050
# theses are GUIDs edited to look right to the parsing and validation code.
51-
endpoint = \
52-
"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/" \
53-
"b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360" \
51+
endpoint = (
52+
"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/"
53+
"b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360"
5454
"&subscription-key=048ec46dc58e495482b0c447cfdbd291&q="
55+
)
5556

5657
# Act
5758
app = LuisApplication.from_application_endpoint(endpoint)

libraries/botbuilder-ai/tests/luis/luis_recognizer_test.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ def __init__(self, *args, **kwargs):
5555

5656
def test_luis_recognizer_construction(self):
5757
# Arrange
58-
endpoint = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/" \
59-
"b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360" \
60-
"&subscription-key=048ec46dc58e495482b0c447cfdbd291&q="
58+
endpoint = (
59+
"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/"
60+
"b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360"
61+
"&subscription-key=048ec46dc58e495482b0c447cfdbd291&q="
62+
)
6163

6264
# Act
6365
recognizer = LuisRecognizer(endpoint)
@@ -69,9 +71,11 @@ def test_luis_recognizer_construction(self):
6971
self.assertEqual("https://westus.api.cognitive.microsoft.com", app.endpoint)
7072

7173
def test_luis_recognizer_timeout(self):
72-
endpoint = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/" \
73-
"b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360" \
74-
"&subscription-key=048ec46dc58e495482b0c447cfdbd291&q="
74+
endpoint = (
75+
"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/"
76+
"b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360"
77+
"&subscription-key=048ec46dc58e495482b0c447cfdbd291&q="
78+
)
7579
expected_timeout = 300
7680
options_with_timeout = LuisPredictionOptions(timeout=expected_timeout * 1000)
7781

@@ -436,9 +440,11 @@ def test_telemetry_construction(self):
436440
# Arrange
437441
# Note this is NOT a real LUIS application ID nor a real LUIS subscription-key
438442
# theses are GUIDs edited to look right to the parsing and validation code.
439-
endpoint = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/" \
440-
"b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360" \
441-
"&subscription-key=048ec46dc58e495482b0c447cfdbd291&q="
443+
endpoint = (
444+
"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/"
445+
"b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360"
446+
"&subscription-key=048ec46dc58e495482b0c447cfdbd291&q="
447+
)
442448

443449
# Act
444450
recognizer = LuisRecognizer(endpoint)

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
QnATelemetryConstants,
2020
QueryResult,
2121
)
22-
from botbuilder.core import (
23-
BotAdapter,
24-
BotTelemetryClient,
25-
TurnContext,
26-
)
22+
from botbuilder.core import BotAdapter, BotTelemetryClient, TurnContext
2723
from botbuilder.core.adapters import TestAdapter
2824
from botbuilder.schema import (
2925
Activity,
@@ -40,7 +36,9 @@ def __init__(self, request):
4036

4137
self.on_send_activities(self.capture_sent_activities)
4238

43-
async def capture_sent_activities(self, context: TurnContext, activities, next): # pylint: disable=unused-argument
39+
async def capture_sent_activities(
40+
self, context: TurnContext, activities, next
41+
): # pylint: disable=unused-argument
4442
self.sent += activities
4543
context.responded = True
4644

@@ -722,7 +720,7 @@ def _get_context(question: str, bot_adapter: BotAdapter) -> TurnContext:
722720
return TurnContext(test_adapter, activity)
723721

724722
class OverrideTelemetry(QnAMaker):
725-
def __init__(
723+
def __init__( # pylint: disable=useless-super-delegation
726724
self,
727725
endpoint: QnAMakerEndpoint,
728726
options: QnAMakerOptions,
@@ -738,10 +736,10 @@ def __init__(
738736
log_personal_information,
739737
)
740738

741-
async def on_qna_result(
739+
async def on_qna_result( # pylint: disable=unused-argument
742740
self,
743741
query_results: [QueryResult],
744-
turn_context: TurnContext, # pylint: disable=unused-argument
742+
turn_context: TurnContext,
745743
telemetry_properties: Dict[str, str] = None,
746744
telemetry_metrics: Dict[str, float] = None,
747745
):
@@ -762,7 +760,7 @@ async def on_qna_result(
762760
)
763761

764762
class OverrideFillTelemetry(QnAMaker):
765-
def __init__(
763+
def __init__( # pylint: disable=useless-super-delegation
766764
self,
767765
endpoint: QnAMakerEndpoint,
768766
options: QnAMakerOptions,

libraries/botbuilder-applicationinsights/tests/test_telemetry_waterfall.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def test_none_telemetry_client(self):
3535
self.assertEqual(type(dialog.telemetry_client), NullTelemetryClient)
3636

3737
@patch("botbuilder.applicationinsights.ApplicationInsightsTelemetryClient")
38-
async def test_execute_sequence_waterfall_steps(self, MockTelemetry): # pylint: disable=invalid-name
38+
async def test_execute_sequence_waterfall_steps( # pylint: disable=invalid-name
39+
self, MockTelemetry
40+
):
3941
# arrange
4042

4143
# Create new ConversationState with MemoryStorage and register the state as middleware.
@@ -91,7 +93,9 @@ async def exec_test(turn_context: TurnContext) -> None:
9193
self.assert_telemetry_calls(telemetry, telemetry_calls)
9294

9395
@patch("botbuilder.applicationinsights.ApplicationInsightsTelemetryClient")
94-
async def test_ensure_end_dialog_called(self, MockTelemetry): # pylint: disable=invalid-name
96+
async def test_ensure_end_dialog_called(
97+
self, MockTelemetry
98+
): # pylint: disable=invalid-name
9599
# arrange
96100

97101
# Create new ConversationState with MemoryStorage and register the state as middleware.
@@ -150,7 +154,8 @@ async def exec_test(turn_context: TurnContext) -> None:
150154
def assert_telemetry_call(
151155
self, telemetry_mock, index: int, event_name: str, props: Dict[str, str]
152156
) -> None:
153-
args, kwargs = telemetry_mock.track_event.call_args_list[index] # pylint: disable=unused-variable
157+
# pylint: disable=unused-variable
158+
args, kwargs = telemetry_mock.track_event.call_args_list[index]
154159
self.assertEqual(args[0], event_name)
155160

156161
for key, val in props.items():

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ def __create_dict(self, store_item: StoreItem) -> Dict:
248248
"""
249249
# read the content
250250
non_magic_attr = [
251-
attr for attr in dir(store_item) if not attr.startswith("_") or attr.__eq__("e_tag")
251+
attr
252+
for attr in dir(store_item)
253+
if not attr.startswith("_") or attr.__eq__("e_tag")
252254
]
253255
# loop through attributes and write and return a dict
254256
return {attr: getattr(store_item, attr) for attr in non_magic_attr}
@@ -294,7 +296,9 @@ def __create_db_and_container(self):
294296
self.database = self._get_or_create_database(self.client, db_id)
295297
self.container = self._get_or_create_container(self.client, container_name)
296298

297-
def _get_or_create_database(self, doc_client, id) -> str: # pylint: disable=invalid-name
299+
def _get_or_create_database( # pylint: disable=invalid-name
300+
self, doc_client, id
301+
) -> str:
298302
"""Return the database link.
299303
300304
Check if the database exists or create the database.
@@ -345,8 +349,6 @@ def _get_or_create_container(self, doc_client, container) -> str:
345349

346350
# Create a container if it didn't exist
347351
res = doc_client.CreateContainer(
348-
self.__database_link,
349-
{"id": container},
350-
self._container_creation_options,
352+
self.__database_link, {"id": container}, self._container_creation_options
351353
)
352354
return res["id"]

libraries/botbuilder-core/botbuilder/core/activity_handler.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ async def on_turn(self, turn_context: TurnContext):
3232
else:
3333
await self.on_unrecognized_activity_type(turn_context)
3434

35-
async def on_message_activity(self, turn_context: TurnContext): # pylint: disable=unused-argument
35+
async def on_message_activity( # pylint: disable=unused-argument
36+
self, turn_context: TurnContext
37+
):
3638
return
3739

3840
async def on_conversation_update_activity(self, turn_context: TurnContext):
@@ -68,11 +70,17 @@ async def on_event_activity(self, turn_context: TurnContext):
6870

6971
return await self.on_event(turn_context)
7072

71-
async def on_token_response_event(self, turn_context: TurnContext): # pylint: disable=unused-argument
73+
async def on_token_response_event( # pylint: disable=unused-argument
74+
self, turn_context: TurnContext
75+
):
7276
return
7377

74-
async def on_event(self, turn_context: TurnContext): # pylint: disable=unused-argument
78+
async def on_event( # pylint: disable=unused-argument
79+
self, turn_context: TurnContext
80+
):
7581
return
7682

77-
async def on_unrecognized_activity_type(self, turn_context: TurnContext): # pylint: disable=unused-argument
83+
async def on_unrecognized_activity_type( # pylint: disable=unused-argument
84+
self, turn_context: TurnContext
85+
):
7886
return

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(
5858
logic: Coroutine = None,
5959
conversation: ConversationReference = None,
6060
send_trace_activity: bool = False,
61-
): # pylint: disable=unused-argument
61+
): # pylint: disable=unused-argument
6262
"""
6363
Creates a new TestAdapter instance.
6464
:param logic:
@@ -242,10 +242,7 @@ async def get_user_token(
242242
magic_code_record = list(
243243
filter(lambda x: key.equals_key(x.key), self._magic_codes)
244244
)
245-
if (
246-
magic_code_record
247-
and magic_code_record[0].magic_code == magic_code
248-
):
245+
if magic_code_record and magic_code_record[0].magic_code == magic_code:
249246
# Move the token to long term dictionary.
250247
self.add_user_token(
251248
connection_name,
@@ -269,7 +266,9 @@ async def get_user_token(
269266
# Not found.
270267
return None
271268

272-
async def sign_out_user(self, context: TurnContext, connection_name: str, user_id: str = None):
269+
async def sign_out_user(
270+
self, context: TurnContext, connection_name: str, user_id: str = None
271+
):
273272
channel_id = context.activity.channel_id
274273
user_id = context.activity.from_property.id
275274

@@ -286,8 +285,10 @@ async def sign_out_user(self, context: TurnContext, connection_name: str, user_i
286285
async def get_oauth_sign_in_link(
287286
self, context: TurnContext, connection_name: str
288287
) -> str:
289-
return f"https://fake.com/oauthsignin" \
288+
return (
289+
f"https://fake.com/oauthsignin"
290290
f"/{connection_name}/{context.activity.channel_id}/{context.activity.from_property.id}"
291+
)
291292

292293
async def get_aad_tokens(
293294
self, context: TurnContext, connection_name: str, resource_urls: List[str]

libraries/botbuilder-core/botbuilder/core/conversation_state.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ def get_storage_key(self, turn_context: TurnContext) -> object:
2020
channel_id = turn_context.activity.channel_id or self.__raise_type_error(
2121
"invalid activity-missing channel_id"
2222
)
23-
conversation_id = turn_context.activity.conversation.id or self.__raise_type_error(
24-
"invalid activity-missing conversation.id"
23+
conversation_id = (
24+
turn_context.activity.conversation.id
25+
or self.__raise_type_error("invalid activity-missing conversation.id")
2526
)
2627

2728
storage_key = None

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
class Middleware(ABC):
1212
@abstractmethod
13-
def on_process_request(self, context: TurnContext, logic: Callable[[TurnContext], Awaitable]):
13+
def on_process_request(
14+
self, context: TurnContext, logic: Callable[[TurnContext], Awaitable]
15+
):
1416
pass
1517

1618

@@ -22,7 +24,9 @@ def __init__(self, anonymous_handler):
2224
)
2325
self._to_call = anonymous_handler
2426

25-
def on_process_request(self, context: TurnContext, logic: Callable[[TurnContext], Awaitable]):
27+
def on_process_request(
28+
self, context: TurnContext, logic: Callable[[TurnContext], Awaitable]
29+
):
2630
return self._to_call(context, logic)
2731

2832

libraries/botbuilder-core/botbuilder/core/state_property_accessor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
class StatePropertyAccessor(ABC):
1010
@abstractmethod
11-
async def get(self, turn_context: TurnContext, default_value_factory=None) -> object:
11+
async def get(
12+
self, turn_context: TurnContext, default_value_factory=None
13+
) -> object:
1214
"""
1315
Get the property value from the source
1416
:param turn_context: Turn Context.

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ def __init__(self, adapter_or_context, request: Activity = None):
2020
self._activity = request
2121
self.responses: List[Activity] = []
2222
self._services: dict = {}
23-
self._on_send_activities: Callable[["TurnContext", List[Activity], Callable], List[ResourceResponse]] = []
24-
self._on_update_activity: Callable[["TurnContext", Activity, Callable], ResourceResponse] = []
25-
self._on_delete_activity: Callable[["TurnContext", ConversationReference, Callable], None] = []
23+
self._on_send_activities: Callable[
24+
["TurnContext", List[Activity], Callable], List[ResourceResponse]
25+
] = []
26+
self._on_update_activity: Callable[
27+
["TurnContext", Activity, Callable], ResourceResponse
28+
] = []
29+
self._on_delete_activity: Callable[
30+
["TurnContext", ConversationReference, Callable], None
31+
] = []
2632
self._responded: bool = False
2733

2834
if self.adapter is None:
@@ -158,9 +164,7 @@ async def callback(context: "TurnContext", output):
158164
self._on_send_activities, output, callback(self, output)
159165
)
160166

161-
return (
162-
result[0] if result else ResourceResponse()
163-
)
167+
return result[0] if result else ResourceResponse()
164168

165169
async def update_activity(self, activity: Activity):
166170
"""

libraries/botbuilder-core/botbuilder/core/user_token_provider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ async def get_user_token(
2424
raise NotImplementedError()
2525

2626
@abstractmethod
27-
async def sign_out_user(self, context: TurnContext, connection_name: str, user_id: str = None):
27+
async def sign_out_user(
28+
self, context: TurnContext, connection_name: str, user_id: str = None
29+
):
2830
"""
2931
Signs the user out with the token server.
3032
:param context:

libraries/botbuilder-core/tests/call_counting_middleware.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class CallCountingMiddleware(Middleware):
99
def __init__(self):
1010
self.counter = 0
1111

12-
def on_process_request(self, context: TurnContext, logic: Callable[[TurnContext], Awaitable]):
12+
def on_process_request( # pylint: disable=unused-argument
13+
self, context: TurnContext, logic: Callable[[TurnContext], Awaitable]
14+
):
1315
self.counter += 1
1416
logic()

0 commit comments

Comments
 (0)
0