Skip to content

Commit b00a4f0

Browse files
committed
more linting
1 parent 66c9ebd commit b00a4f0

24 files changed

+102
-103
lines changed

docs/src/api/make_pages.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
nav = mkdocs_gen_files.Nav()
1010
for path in sorted(Path(package).glob("**/*.py")):
1111
with mkdocs_gen_files.open(f"api/{path.with_suffix('')}.md", "w") as f:
12-
module_path = ".".join(
13-
[p for p in path.with_suffix("").parts if p != "__init__"]
14-
)
12+
module_path = ".".join([p for p in path.with_suffix("").parts if p != "__init__"])
1513
print(f"::: {module_path}", file=f)
1614
nav[path.parts] = f"{path.with_suffix('')}.md"
1715

docs/src/tutorials/dj-top.ipynb

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@
229229
" home_city=city,\n",
230230
" home_state=state,\n",
231231
" home_zip=zipcode,\n",
232-
" date_of_birth=str(\n",
233-
" fake.date_time_between(start_date=\"-35y\", end_date=\"-15y\").date()\n",
234-
" ),\n",
232+
" date_of_birth=str(fake.date_time_between(start_date=\"-35y\", end_date=\"-15y\").date()),\n",
235233
" home_phone=fake.phone_number()[:20],\n",
236234
" )"
237235
]
@@ -261,9 +259,7 @@
261259
"\n",
262260
"StudentMajor.insert(\n",
263261
" {**s, **d, \"declare_date\": fake.date_between(start_date=datetime.date(1999, 1, 1))}\n",
264-
" for s, d in zip(\n",
265-
" Student.fetch(\"KEY\"), random.choices(Department.fetch(\"KEY\"), k=len(Student()))\n",
266-
" )\n",
262+
" for s, d in zip(Student.fetch(\"KEY\"), random.choices(Department.fetch(\"KEY\"), k=len(Student())))\n",
267263
" if random.random() < 0.75\n",
268264
")\n",
269265
"\n",
@@ -318,17 +314,11 @@
318314
" ]\n",
319315
")\n",
320316
"\n",
321-
"Term.insert(\n",
322-
" dict(term_year=year, term=term)\n",
323-
" for year in range(1999, 2019)\n",
324-
" for term in [\"Spring\", \"Summer\", \"Fall\"]\n",
325-
")\n",
317+
"Term.insert(dict(term_year=year, term=term) for year in range(1999, 2019) for term in [\"Spring\", \"Summer\", \"Fall\"])\n",
326318
"\n",
327319
"Term().fetch(order_by=(\"term_year DESC\", \"term DESC\"), as_dict=True, limit=1)[0]\n",
328320
"\n",
329-
"CurrentTerm().insert1(\n",
330-
" {**Term().fetch(order_by=(\"term_year DESC\", \"term DESC\"), as_dict=True, limit=1)[0]}\n",
331-
")\n",
321+
"CurrentTerm().insert1({**Term().fetch(order_by=(\"term_year DESC\", \"term DESC\"), as_dict=True, limit=1)[0]})\n",
332322
"\n",
333323
"\n",
334324
"def make_section(prob):\n",
@@ -372,10 +362,7 @@
372362
" sections = ((Section & term) - (Course & (Enroll & student))).fetch(\"KEY\")\n",
373363
" if sections:\n",
374364
" Enroll.insert(\n",
375-
" {**student, **section}\n",
376-
" for section in random.sample(\n",
377-
" sections, random.randrange(min(5, len(sections)))\n",
378-
" )\n",
365+
" {**student, **section} for section in random.sample(sections, random.randrange(min(5, len(sections))))\n",
379366
" )\n",
380367
"\n",
381368
"# assign random grades\n",
@@ -385,10 +372,7 @@
385372
"random.shuffle(grade_keys)\n",
386373
"grade_keys = grade_keys[: len(grade_keys) * 9 // 10]\n",
387374
"\n",
388-
"Grade.insert(\n",
389-
" {**key, \"grade\": grade}\n",
390-
" for key, grade in zip(grade_keys, random.choices(grades, k=len(grade_keys)))\n",
391-
")"
375+
"Grade.insert({**key, \"grade\": grade} for key, grade in zip(grade_keys, random.choices(grades, k=len(grade_keys))))"
392376
]
393377
},
394378
{
@@ -544,9 +528,7 @@
544528
}
545529
],
546530
"source": [
547-
"(Grade * LetterGrade) & \"term_year='2018'\" & dj.Top(\n",
548-
" limit=5, order_by=\"points DESC\", offset=5\n",
549-
")"
531+
"(Grade * LetterGrade) & \"term_year='2018'\" & dj.Top(limit=5, order_by=\"points DESC\", offset=5)"
550532
]
551533
},
552534
{
@@ -566,11 +548,7 @@
566548
}
567549
],
568550
"source": [
569-
"(\n",
570-
" (LetterGrade * Grade)\n",
571-
" & \"term_year='2018'\"\n",
572-
" & dj.Top(limit=10, order_by=\"points DESC\", offset=0)\n",
573-
").make_sql()"
551+
"((LetterGrade * Grade) & \"term_year='2018'\" & dj.Top(limit=10, order_by=\"points DESC\", offset=0)).make_sql()"
574552
]
575553
},
576554
{
@@ -590,11 +568,7 @@
590568
}
591569
],
592570
"source": [
593-
"(\n",
594-
" (Grade * LetterGrade)\n",
595-
" & \"term_year='2018'\"\n",
596-
" & dj.Top(limit=20, order_by=\"points DESC\", offset=0)\n",
597-
").make_sql()"
571+
"((Grade * LetterGrade) & \"term_year='2018'\" & dj.Top(limit=20, order_by=\"points DESC\", offset=0)).make_sql()"
598572
]
599573
},
600574
{
@@ -800,9 +774,7 @@
800774
}
801775
],
802776
"source": [
803-
"(Grade * LetterGrade) & \"term_year='2018'\" & dj.Top(\n",
804-
" limit=20, order_by=\"points DESC\", offset=0\n",
805-
")"
777+
"(Grade * LetterGrade) & \"term_year='2018'\" & dj.Top(limit=20, order_by=\"points DESC\", offset=0)"
806778
]
807779
},
808780
{
@@ -1008,9 +980,7 @@
1008980
}
1009981
],
1010982
"source": [
1011-
"(LetterGrade * Grade) & \"term_year='2018'\" & dj.Top(\n",
1012-
" limit=20, order_by=\"points DESC\", offset=0\n",
1013-
")"
983+
"(LetterGrade * Grade) & \"term_year='2018'\" & dj.Top(limit=20, order_by=\"points DESC\", offset=0)"
1014984
]
1015985
},
1016986
{

src/datajoint/autopopulate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _rename_attributes(table, props):
7676
if self._key_source is None:
7777
parents = self.target.parents(primary=True, as_objects=True, foreign_key_info=True)
7878
if not parents:
79-
raise DataJointError("A table must have dependencies " "from its primary key for auto-populate to work")
79+
raise DataJointError("A table must have dependencies from its primary key for auto-populate to work")
8080
self._key_source = _rename_attributes(*parents[0])
8181
for q in parents[1:]:
8282
self._key_source *= _rename_attributes(*q)
@@ -174,7 +174,7 @@ def _jobs_to_do(self, restrictions):
174174
"""
175175
if self.restriction:
176176
raise DataJointError(
177-
"Cannot call populate on a restricted table. " "Instead, pass conditions to populate() as arguments."
177+
"Cannot call populate on a restricted table. Instead, pass conditions to populate() as arguments."
178178
)
179179
todo = self.key_source
180180

src/datajoint/diagram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def make_dot(self):
361361
dest = edge.get_destination()
362362
props = graph.get_edge_data(src, dest)
363363
if props is None:
364-
raise DataJointError("Could not find edge with source " "'{}' and destination '{}'".format(src, dest))
364+
raise DataJointError("Could not find edge with source '{}' and destination '{}'".format(src, dest))
365365
edge.set_color("#00000040")
366366
edge.set_style("solid" if props["primary"] else "dashed")
367367
master_part = graph.nodes[dest]["node_type"] is Part and dest.startswith(src + ".")

src/datajoint/expression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ def proj(self, *attributes, **named_attributes):
358358
"""
359359
named_attributes = {k: translate_attribute(v)[1] for k, v in named_attributes.items()}
360360
# new attributes in parentheses are included again with the new name without removing original
361-
duplication_pattern = re.compile(rf'^\s*\(\s*(?!{"|".join(CONSTANT_LITERALS)})(?P<name>[a-zA-Z_]\w*)\s*\)\s*$')
361+
duplication_pattern = re.compile(rf"^\s*\(\s*(?!{'|'.join(CONSTANT_LITERALS)})(?P<name>[a-zA-Z_]\w*)\s*\)\s*$")
362362
# attributes without parentheses renamed
363-
rename_pattern = re.compile(rf'^\s*(?!{"|".join(CONSTANT_LITERALS)})(?P<name>[a-zA-Z_]\w*)\s*$')
363+
rename_pattern = re.compile(rf"^\s*(?!{'|'.join(CONSTANT_LITERALS)})(?P<name>[a-zA-Z_]\w*)\s*$")
364364
replicate_map = {
365365
k: m.group("name") for k, m in ((k, duplication_pattern.match(v)) for k, v in named_attributes.items()) if m
366366
}
@@ -562,7 +562,7 @@ def __next__(self):
562562
key = self._iter_keys.pop(0)
563563
except AttributeError:
564564
# self._iter_keys is missing because __iter__ has not been called.
565-
raise TypeError("A QueryExpression object is not an iterator. " "Use iter(obj) to create an iterator.")
565+
raise TypeError("A QueryExpression object is not an iterator. Use iter(obj) to create an iterator.")
566566
except IndexError:
567567
raise StopIteration
568568
else:

src/datajoint/external.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def put(self, blob):
171171
self._upload_buffer(blob, self._make_uuid_path(uuid))
172172
# insert tracking info
173173
self.connection.query(
174-
"INSERT INTO {tab} (hash, size) VALUES (%s, {size}) ON DUPLICATE KEY " "UPDATE timestamp=CURRENT_TIMESTAMP".format(
174+
"INSERT INTO {tab} (hash, size) VALUES (%s, {size}) ON DUPLICATE KEY UPDATE timestamp=CURRENT_TIMESTAMP".format(
175175
tab=self.full_table_name, size=len(blob)
176176
),
177177
args=(uuid.bytes,),
@@ -394,7 +394,7 @@ def delete(
394394
:return: if deleting external files, returns errors
395395
"""
396396
if delete_external_files not in (True, False):
397-
raise DataJointError("The delete_external_files argument must be set to either " "True or False in delete()")
397+
raise DataJointError("The delete_external_files argument must be set to either True or False in delete()")
398398

399399
if not delete_external_files:
400400
self.unused().delete_quick()

src/datajoint/fetch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,16 @@ def __call__(
160160
# format should not be specified with attrs or is_dict=True
161161
if format is not None and (as_dict or attrs):
162162
raise DataJointError(
163-
"Cannot specify output format when as_dict=True or " "when attributes are selected to be fetched separately."
163+
"Cannot specify output format when as_dict=True or when attributes are selected to be fetched separately."
164164
)
165165
if format not in {None, "array", "frame"}:
166-
raise DataJointError("Fetch output format must be in " '{{"array", "frame"}} but "{}" was given'.format(format))
166+
raise DataJointError('Fetch output format must be in {{"array", "frame"}} but "{}" was given'.format(format))
167167

168168
if not (attrs or as_dict) and format is None:
169169
format = config["fetch_format"] # default to array
170170
if format not in {"array", "frame"}:
171171
raise DataJointError(
172-
'Invalid entry "{}" in datajoint.config["fetch_format"]: ' 'use "array" or "frame"'.format(format)
172+
'Invalid entry "{}" in datajoint.config["fetch_format"]: use "array" or "frame"'.format(format)
173173
)
174174

175175
get = partial(

src/datajoint/heading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def _init_from_database(self):
308308
"#migration-between-datajoint-v0-11-and-v0-12"
309309
)
310310
raise DataJointError(
311-
"Legacy datatype `{type}`. Migrate your external stores to " "datajoint 0.12: {url}".format(
311+
"Legacy datatype `{type}`. Migrate your external stores to datajoint 0.12: {url}".format(
312312
url=url, **attr
313313
)
314314
)

src/datajoint/schemas.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def activate(
124124
if not self.exists:
125125
if not self.create_schema or not self.database:
126126
raise DataJointError(
127-
"Database `{name}` has not yet been declared. " "Set argument create_schema=True to create it.".format(
127+
"Database `{name}` has not yet been declared. Set argument create_schema=True to create it.".format(
128128
name=schema_name
129129
)
130130
)
@@ -134,7 +134,7 @@ def activate(
134134
self.connection.query("CREATE DATABASE `{name}`".format(name=schema_name))
135135
except AccessError:
136136
raise DataJointError(
137-
"Schema `{name}` does not exist and could not be created. " "Check permissions.".format(name=schema_name)
137+
"Schema `{name}` does not exist and could not be created. Check permissions.".format(name=schema_name)
138138
)
139139
else:
140140
self.log("created")
@@ -220,7 +220,7 @@ def _decorate_table(self, table_class, context, assert_declared=False):
220220
if len(contents) > len(instance):
221221
if instance.heading.has_autoincrement:
222222
warnings.warn(
223-
("Contents has changed but cannot be inserted because " "{table} has autoincrement.").format(
223+
("Contents has changed but cannot be inserted because {table} has autoincrement.").format(
224224
table=instance.__class__.__name__
225225
)
226226
)
@@ -317,7 +317,7 @@ def drop(self, force=False):
317317
logger.debug("Schema `{database}` was dropped successfully.".format(database=self.database))
318318
except AccessError:
319319
raise AccessError(
320-
"An attempt to drop schema `{database}` " "has failed. Check permissions.".format(database=self.database)
320+
"An attempt to drop schema `{database}` has failed. Check permissions.".format(database=self.database)
321321
)
322322

323323
@property
@@ -329,7 +329,7 @@ def exists(self):
329329
raise DataJointError("Schema must be activated first.")
330330
return bool(
331331
self.connection.query(
332-
"SELECT schema_name " "FROM information_schema.schemata " "WHERE schema_name = '{database}'".format(
332+
"SELECT schema_name FROM information_schema.schemata WHERE schema_name = '{database}'".format(
333333
database=self.database
334334
)
335335
).rowcount
@@ -382,7 +382,7 @@ def replace(s):
382382
)
383383

384384
return ("" if tier == "Part" else "\n@schema\n") + (
385-
"{indent}class {class_name}(dj.{tier}):\n" '{indent} definition = """\n' '{indent} {defi}"""'
385+
'{indent}class {class_name}(dj.{tier}):\n{indent} definition = """\n{indent} {defi}"""'
386386
).format(
387387
class_name=class_name,
388388
indent=indent,
@@ -476,6 +476,6 @@ def list_schemas(connection=None):
476476
return [
477477
r[0]
478478
for r in (connection or conn()).query(
479-
"SELECT schema_name " "FROM information_schema.schemata " 'WHERE schema_name <> "information_schema"'
479+
'SELECT schema_name FROM information_schema.schemata WHERE schema_name <> "information_schema"'
480480
)
481481
]

src/datajoint/table.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def declare(self, context=None):
9393
not allowed.
9494
"""
9595
if self.connection.in_transaction:
96-
raise DataJointError("Cannot declare new tables inside a transaction, " "e.g. from inside a populate/make call")
96+
raise DataJointError("Cannot declare new tables inside a transaction, e.g. from inside a populate/make call")
9797
# Enforce strict CamelCase #1150
9898
if not is_camel_case(self.class_name):
9999
raise DataJointError(
@@ -118,9 +118,7 @@ def alter(self, prompt=True, context=None):
118118
Alter the table definition from self.definition
119119
"""
120120
if self.connection.in_transaction:
121-
raise DataJointError(
122-
"Cannot update table declaration inside a transaction, " "e.g. from inside a populate/make call"
123-
)
121+
raise DataJointError("Cannot update table declaration inside a transaction, e.g. from inside a populate/make call")
124122
if context is None:
125123
frame = inspect.currentframe().f_back
126124
context = dict(frame.f_globals, **frame.f_locals)
@@ -569,7 +567,7 @@ def cascade(table):
569567
if transaction:
570568
self.connection.cancel_transaction()
571569
raise DataJointError(
572-
"Attempt to delete part table {part} before deleting from " "its master {master} first.".format(
570+
"Attempt to delete part table {part} before deleting from its master {master} first.".format(
573571
part=part, master=master
574572
)
575573
)
@@ -614,7 +612,7 @@ def drop(self):
614612
"""
615613
if self.restriction:
616614
raise DataJointError(
617-
"A table with an applied restriction cannot be dropped." " Call drop() on the unrestricted Table."
615+
"A table with an applied restriction cannot be dropped. Call drop() on the unrestricted Table."
618616
)
619617
self.connection.dependencies.load()
620618
do_drop = True
@@ -625,7 +623,7 @@ def drop(self):
625623
master = get_master(part)
626624
if master and master not in tables:
627625
raise DataJointError(
628-
"Attempt to drop part table {part} before dropping " "its master. Drop {master} first.".format(
626+
"Attempt to drop part table {part} before dropping its master. Drop {master} first.".format(
629627
part=part, master=master
630628
)
631629
)
@@ -799,8 +797,9 @@ def check_fields(fields):
799797
try:
800798
if len(row) != len(self.heading):
801799
raise DataJointError(
802-
"Invalid insert argument. Incorrect number of attributes: "
803-
"{given} given; {expected} expected".format(given=len(row), expected=len(self.heading))
800+
"Invalid insert argument. Incorrect number of attributes: {given} given; {expected} expected".format(
801+
given=len(row), expected=len(self.heading)
802+
)
804803
)
805804
except TypeError:
806805
raise DataJointError("Datatype %s cannot be inserted" % type(row))

0 commit comments

Comments
 (0)