Skip to content

Commit 3533c01

Browse files
committed
Linting
1 parent d24d2c8 commit 3533c01

File tree

6 files changed

+80
-38
lines changed

6 files changed

+80
-38
lines changed

notion/block.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,7 @@ def get_backlinks(self):
546546
"""
547547
Returns a list of blocks that referencing the current PageBlock. Note that only PageBlocks support backlinks.
548548
"""
549-
data = self._client.post(
550-
"getBacklinksForBlock",
551-
{"blockId": self.id},
552-
).json()
549+
data = self._client.post("getBacklinksForBlock", {"blockId": self.id}).json()
553550
backlinks = []
554551
for block in data.get("backlinks") or []:
555552
mention = block.get("mentioned_from")
@@ -560,6 +557,7 @@ def get_backlinks(self):
560557
backlinks.append(self._client.get_block(block_id))
561558
return backlinks
562559

560+
563561
class BulletedListBlock(BasicBlock):
564562

565563
_type = "bulleted_list"

notion/client.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ def create_session(client_specified_retry=None):
4141
backoff_factor=0.3,
4242
status_forcelist=(502, 503, 504),
4343
# CAUTION: adding 'POST' to this list which is not technically idempotent
44-
method_whitelist=("POST", "HEAD", "TRACE", "GET", "PUT", "OPTIONS", "DELETE"),
44+
method_whitelist=(
45+
"POST",
46+
"HEAD",
47+
"TRACE",
48+
"GET",
49+
"PUT",
50+
"OPTIONS",
51+
"DELETE",
52+
),
4553
)
4654
adapter = HTTPAdapter(max_retries=retry)
4755
session.mount("https://", adapter)
@@ -91,10 +99,10 @@ def start_monitoring(self):
9199

92100
def _set_token(self, email=None, password=None):
93101
if not email:
94-
email = input(f'Enter Your Notion Email\n')
102+
email = input("Enter your Notion email address:\n")
95103
if not password:
96-
password = getpass(f'Enter Your Notion Password\n')
97-
self.post("loginWithEmail", {"email":email,"password":password}).json()
104+
password = getpass("Enter your Notion password:\n")
105+
self.post("loginWithEmail", {"email": email, "password": password}).json()
98106

99107
def _update_user_info(self):
100108
records = self.post("loadUserContent", {}).json()["recordMap"]

notion/collection.py

+35-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
from .markdown import markdown_to_notion, notion_to_markdown
1111
from .operations import build_operation
1212
from .records import Record
13-
from .utils import add_signed_prefix_as_needed, extract_id, remove_signed_prefix_as_needed, slugify
13+
from .utils import (
14+
add_signed_prefix_as_needed,
15+
extract_id,
16+
remove_signed_prefix_as_needed,
17+
slugify,
18+
)
1419

1520

1621
class NotionDate(object):
@@ -97,8 +102,18 @@ def to_notion(self):
97102

98103

99104
class NotionSelect(object):
100-
valid_colors = ["default", "gray", "brown", "orange", "yellow",
101-
"green", "blue", "purple", "pink", "red"]
105+
valid_colors = [
106+
"default",
107+
"gray",
108+
"brown",
109+
"orange",
110+
"yellow",
111+
"green",
112+
"blue",
113+
"purple",
114+
"pink",
115+
"red",
116+
]
102117
id = None
103118
color = "default"
104119
value = None
@@ -116,11 +131,7 @@ def set_color(self, color):
116131
return color
117132

118133
def to_dict(self):
119-
return {
120-
"id": self.id,
121-
"value": self.value,
122-
"color": self.color
123-
}
134+
return {"id": self.id, "value": self.value, "color": self.color}
124135

125136

126137
class Collection(Record):
@@ -320,7 +331,9 @@ def _normalize_query_data(data, collection, recursing=False):
320331
if not recursing:
321332
data = deepcopy(data)
322333
if isinstance(data, list):
323-
return [_normalize_query_data(item, collection, recursing=True) for item in data]
334+
return [
335+
_normalize_query_data(item, collection, recursing=True) for item in data
336+
]
324337
elif isinstance(data, dict):
325338
# convert slugs to property ids
326339
if "property" in data:
@@ -348,7 +361,9 @@ def __init__(
348361
calendar_by="",
349362
group_by="",
350363
):
351-
assert not (aggregate and aggregations), "Use only one of `aggregate` or `aggregations` (old vs new format)"
364+
assert not (
365+
aggregate and aggregations
366+
), "Use only one of `aggregate` or `aggregations` (old vs new format)"
352367
self.collection = collection
353368
self.collection_view = collection_view
354369
self.search = search
@@ -379,7 +394,7 @@ def execute(self):
379394
calendar_by=self.calendar_by,
380395
group_by=self.group_by,
381396
),
382-
self
397+
self,
383398
)
384399

385400

@@ -497,7 +512,9 @@ def _convert_notion_to_python(self, val, prop):
497512
if prop["type"] in ["file"]:
498513
val = (
499514
[
500-
add_signed_prefix_as_needed(item[1][0][1], client=self._client, id=self.id)
515+
add_signed_prefix_as_needed(
516+
item[1][0][1], client=self._client, id=self.id
517+
)
501518
for item in val
502519
if item[0] != ","
503520
]
@@ -542,7 +559,9 @@ def set_property(self, identifier, val):
542559
if prop["type"] in ["select"] or prop["type"] in ["multi_select"]:
543560
schema_update, prop = self.collection.check_schema_select_options(prop, val)
544561
if schema_update:
545-
self.collection.set("schema.{}.options".format(prop["id"]), prop["options"])
562+
self.collection.set(
563+
"schema.{}.options".format(prop["id"]), prop["options"]
564+
)
546565

547566
path, val = self._convert_python_to_notion(val, prop, identifier=identifier)
548567

@@ -686,7 +705,9 @@ def __init__(self, collection, result, query):
686705
self._client = collection._client
687706
self._block_ids = self._get_block_ids(result)
688707
self.aggregates = result.get("aggregationResults", [])
689-
self.aggregate_ids = [agg.get("id") for agg in (query.aggregate or query.aggregations)]
708+
self.aggregate_ids = [
709+
agg.get("id") for agg in (query.aggregate or query.aggregations)
710+
]
690711
self.query = query
691712

692713
def _get_block_ids(self, result):

notion/logger.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
def enable_debugging():
1313
set_log_level(logging.DEBUG)
1414

15+
1516
def set_log_level(level):
1617
logger.setLevel(level)
1718
handler.setLevel(level)
@@ -35,4 +36,8 @@ def set_log_level(level):
3536
elif NOTIONPY_LOG_LEVEL == "error":
3637
set_log_level(logging.ERROR)
3738
else:
38-
raise Exception("Invalid value for environment variable NOTIONPY_LOG_LEVEL: {}".format(NOTIONPY_LOG_LEVEL))
39+
raise Exception(
40+
"Invalid value for environment variable NOTIONPY_LOG_LEVEL: {}".format(
41+
NOTIONPY_LOG_LEVEL
42+
)
43+
)

notion/smoke_test.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def run_live_smoke_test(token_v2, parent_page_url_or_id):
2424
col1kid = col1.children.add_new(
2525
TextBlock, title="Some formatting: *italic*, **bold**, ***both***!"
2626
)
27-
assert col1kid.title.replace("_", "*") == "Some formatting: *italic*, **bold**, ***both***!"
27+
assert (
28+
col1kid.title.replace("_", "*")
29+
== "Some formatting: *italic*, **bold**, ***both***!"
30+
)
2831
assert col1kid.title_plaintext == "Some formatting: italic, bold, both!"
2932
col2.children.add_new(TodoBlock, title="I should be unchecked")
3033
col2.children.add_new(TodoBlock, title="I should be checked", checked=True)
@@ -112,7 +115,7 @@ def run_live_smoke_test(token_v2, parent_page_url_or_id):
112115
start = datetime.strptime("2020-01-01 09:30", "%Y-%m-%d %H:%M")
113116
end = datetime.strptime("2020-01-05 20:45", "%Y-%m-%d %H:%M")
114117
timezone = "America/Los_Angeles"
115-
reminder= {'unit': 'minute', 'value': 30}
118+
reminder = {"unit": "minute", "value": 30}
116119
row1.some_date = NotionDate(start, end=end, timezone=timezone, reminder=reminder)
117120

118121
# add another row
@@ -134,7 +137,10 @@ def run_live_smoke_test(token_v2, parent_page_url_or_id):
134137

135138
# check that existing options "A" haven't been affected
136139
for prop in ["=d{|", "=d{q"]:
137-
assert cvb.collection.get("schema.{}.options.0.id".format(prop)) == get_collection_schema()[prop]["options"][0]["id"]
140+
assert (
141+
cvb.collection.get("schema.{}.options.0.id".format(prop))
142+
== get_collection_schema()[prop]["options"][0]["id"]
143+
)
138144

139145
# Run a filtered/sorted query using the view's default parameters
140146
result = view.default_query().execute()
@@ -163,17 +169,19 @@ def run_live_smoke_test(token_v2, parent_page_url_or_id):
163169

164170
# Run a "filtered" query
165171
filter_params = {
166-
"filters": [{
167-
"filter": {
168-
"value": {
169-
"type": "exact",
170-
"value": {"table": "notion_user", "id": client.current_user.id}
172+
"filters": [
173+
{
174+
"filter": {
175+
"value": {
176+
"type": "exact",
177+
"value": {"table": "notion_user", "id": client.current_user.id},
178+
},
179+
"operator": "person_does_not_contain",
171180
},
172-
"operator": "person_does_not_contain"
173-
},
174-
"property": "person"
175-
}],
176-
"operator": "and"
181+
"property": "person",
182+
}
183+
],
184+
"operator": "and",
177185
}
178186
result = view.build_query(filter=filter_params).execute()
179187
assert row1 in result
@@ -267,7 +275,7 @@ def get_collection_schema():
267275
"LL[(": {"name": "Person", "type": "person"},
268276
"4Jv$": {"name": "Estimated value", "type": "number"},
269277
"OBcJ": {"name": "Where to?", "type": "url"},
270-
"TwR:": {"name": "Some Date", "type": "date"},
278+
"TwR:": {"name": "Some Date", "type": "date"},
271279
"dV$q": {"name": "Files", "type": "file"},
272280
"title": {"name": "Name", "type": "title"},
273281
}

notion/store.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ def call_query_collection(
312312
group_by="",
313313
):
314314

315-
assert not (aggregate and aggregations), "Use only one of `aggregate` or `aggregations` (old vs new format)"
315+
assert not (
316+
aggregate and aggregations
317+
), "Use only one of `aggregate` or `aggregations` (old vs new format)"
316318

317319
# convert singletons into lists if needed
318320
if isinstance(aggregate, dict):

0 commit comments

Comments
 (0)