8000 azure pylint issues (#267) · sherlock666/botbuilder-python@c6a6a69 · GitHub
[go: up one dir, main page]

Skip to content

Commit c6a6a69

Browse files
authored
azure pylint issues (microsoft#267)
* pylint fixes for azure library code and tests * fix on tests from renaming variable
1 parent cefbc05 commit c6a6a69

File tree

2 files changed

+104
-102
lines changed

2 files changed

+104
-102
lines changed

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

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from typing import Dict, List
1111
from threading import Semaphore
1212
import json
13+
import azure.cosmos.cosmos_client as cosmos_client # pylint: disable=no-name-in-module,import-error
14+
import azure.cosmos.errors as cosmos_errors # pylint: disable=no-name-in-module,import-error
1315
from botbuilder.core.storage import Storage, StoreItem
14-
import azure.cosmos.cosmos_client as cosmos_client
15-
import azure.cosmos.errors as cosmos_errors
1616

1717

1818
class CosmosDbConfig:
@@ -74,13 +74,13 @@ def sanitize_key(key) -> str: 8000
7474

7575
@staticmethod
7676
def truncate_key(key: str) -> str:
77-
MAX_KEY_LEN = 255
77+
max_key_len = 255
7878

79-
if len(key) > MAX_KEY_LEN:
79+
if len(key) > max_key_len:
8080
aux_hash = sha256(key.encode("utf-8"))
8181
aux_hex = aux_hash.hexdigest()
8282

83-
key = key[0 : MAX_KEY_LEN - len(aux_hex)] + aux_hex
83+
key = key[0 : max_key_len - len(aux_hex)] + aux_hex
8484

8585
return key
8686

@@ -101,8 +101,8 @@ def __init__(
101101
self.config.endpoint, {"masterKey": self.config.masterkey}
102102
)
103103
# these are set by the functions that check
104-
# the presence of the db and container or creates them
105-
self.db = None
104+
# the presence of the database and container or creates them
105+
self.database = None
106106
self.container = None
107107
self._database_creation_options = config.database_creation_options
108108
self._container_creation_options = config.container_creation_options
@@ -146,11 +146,11 @@ async def read(self, keys: List[str]) -> Dict[str, object]:
146146
)
147147
# return a dict with a key and a StoreItem
148148
return {r.get("realId"): self.__create_si(r) for r in results}
149-
else:
150-
# No keys passed in, no result to return.
151-
return {}
152-
except TypeError as e:
153-
raise e
149+
150+
# No keys passed in, no result to return.
151+
return {}
152+
except TypeError as error:
153+
raise error
154154

155155
async def write(self, changes: Dict[str, StoreItem]):
156156
"""Save storeitems to storage.
@@ -180,7 +180,7 @@ async def write(self, changes: Dict[str, StoreItem]):
180180
options={"disableAutomaticIdGeneration": True},
181181
)
182182
# if we have an etag, do opt. concurrency replace
183-
elif len(e_tag) > 0:
183+
elif e_tag:
184184
access_condition = {"type": "IfMatch", "condition": e_tag}
185185
self.client.ReplaceItem(
186186
document_link=self.__item_link(
@@ -192,8 +192,8 @@ async def write(self, changes: Dict[str, StoreItem]):
192192
# error when there is no e_tag
193193
else:
194194
raise Exception("cosmosdb_storage.write(): etag missing")
195-
except Exception as e:
196-
raise e
195+
except Exception as error:
196+
raise error
197197

198198
async def delete(self, keys: List[str]):
199199
"""Remove storeitems from storage.
@@ -211,18 +211,18 @@ async def delete(self, keys: List[str]):
211211
options["partitionKey"] = self.config.partition_key
212212

213213
# call the function for each key
214-
for k in keys:
214+
for key in keys:
215215
self.client.DeleteItem(
216-
document_link=self.__item_link(CosmosDbKeyEscape.sanitize_key(k)),
216+
document_link=self.__item_link(CosmosDbKeyEscape.sanitize_key(key)),
217217
options=options,
218218
)
219219
# print(res)
220-
except cosmos_errors.HTTPFailure as h:
220+
except cosmos_errors.HTTPFailure as http_failure:
221221
# print(h.status_code)
222-
if h.status_code != 404:
223-
raise h
224-
except TypeError as e:
225-
raise e
222+
if http_failure.status_code != 404:
223+
raise http_failure
224+
except TypeError as error:
225+
raise error
226226

227227
def __create_si(self, result) -> StoreItem:
228228
"""Create a StoreItem from a result out of CosmosDB.
@@ -238,28 +238,28 @@ def __create_si(self, result) -> StoreItem:
238238
# create and return the StoreItem
239239
return StoreItem(**doc)
240240

241-
def __create_dict(self, si: StoreItem) -> Dict:
241+
def __create_dict(self, store_item: StoreItem) -> Dict:
242242
"""Return the dict of a StoreItem.
243243
244244
This eliminates non_magic attributes and the e_tag.
245245
246-
:param si:
246+
:param store_item:
247247
:return dict:
248248
"""
249249
# read the content
250250
non_magic_attr = [
251-
attr for attr in dir(si) if not attr.startswith("_") or attr.__eq__("e_tag")
251+
attr for attr in dir(store_item) if not attr.startswith("_") or attr.__eq__("e_tag")
252252
]
253253
# loop through attributes and write and return a dict
254-
return {attr: getattr(si, attr) for attr in non_magic_attr}
254+
return {attr: getattr(store_item, attr) for attr in non_magic_attr}
255255

256-
def __item_link(self, id) -> str:
256+
def __item_link(self, identifier) -> str:
257257
"""Return the item link of a item in the container.
258258
259-
:param id:
259+
:param identifier:
260260
:return str:
261261
"""
262-
return self.__container_link + "/docs/" + id
262+
return self.__container_link + "/docs/" + identifier
263263

264264
@property
265265
def __container_link(self) -> str:
@@ -276,28 +276,28 @@ def __database_link(self) -> str:
276276
277277
:return str:
278278
"""
279-
return "dbs/" + self.db
279+
return "dbs/" + self.database
280280

281281
@property
282282
def __container_exists(self) -> bool:
283283
"""Return whether the database and container have been created.
284284
285285
:return bool:
286286
"""
287-
return self.db and self.container
287+
return self.database and self.container
288288

289289
def __create_db_and_container(self):
290290
"""Call the get or create methods."""
291291
with self.__semaphore:
292292
db_id = self.config.database
293293
container_name = self.config.container
294-
self.db = self._get_or_create_database(self.client, db_id)
294+
self.database = self._get_or_create_database(self.client, db_id)
295295
self.container = self._get_or_create_container(self.client, container_name)
296296

297-
def _get_or_create_database(self, doc_client, id) -> str:
297+
def _get_or_create_database(self, doc_client, id) -> str: # pylint: disable=invalid-name
298298
"""Return the database link.
299299
300-
Check if the database exists or create the db.
300+
Check if the database exists or create the database.
301301
302302
:param doc_client:
303303
:param id:
@@ -312,13 +312,13 @@ def _get_or_create_database(self, doc_client, id) -> str:
312312
}
313313
)
314314
)
315-
# if there are results, return the first (db names are unique)
316-
if len(dbs) > 0:
315+
# if there are results, return the first (database names are unique)
316+
if dbs:
317317
return dbs[0]["id"]
318-
else:
319-
# create the database if it didn't exist
320-
res = doc_client.CreateDatabase({"id": id}, self._database_creation_options)
321-
return res["id"]
318+
319+
# create the database if it didn't exist
320+
res = doc_client.CreateDatabase({"id": id}, self._database_creation_options)
321+
return res["id"]
322322

323323
def _get_or_create_container(self, doc_client, container) -> str:
324324
"""Return the container link.
@@ -340,13 +340,13 @@ def _get_or_create_container(self, doc_client, container) -> str:
340340
)
341341
)
342342
# if there are results, return the first (container names are unique)
343-
if len(containers) > 0:
343+
if containers:
344344
return containers[0]["id"]
345-
else:
346-
# Create a container if it didn't exist
347-
res = doc_client.CreateContainer(
348-
self.__database_link,
349-
{"id": container},
350-
self._container_creation_options,
351-
)
352-
return res["id"]
345+
346+
# Create a container if it didn't exist
347+
res = doc_client.CreateContainer(
348+
self.__database_link,
349+
{"id": container},
350+
self._container_creation_options,
351+
)
352+
return res["id"]

0 commit comments

Comments
 (0)
0