Skip to content

Commit 6c935df

Browse files
formatting, use modern python features
Co-authored-by: Mark Mayo <mark@there.co.nz>
1 parent 3b9396d commit 6c935df

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

backend/import.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import json
3+
import sys
34
from pathlib import Path
45
from typing import Optional
56
from uuid import UUID
@@ -168,7 +169,7 @@ def main():
168169
input_file_path = Path(args.input_file_path)
169170
if not input_file_path.exists() or not input_file_path.is_file():
170171
print("Invalid input file:", args.input_file_path)
171-
exit(1)
172+
sys.exit(1)
172173

173174
dry_run = args.dry_run
174175
num_imported = import_file(

backend/oasst_backend/models/payload_column_type.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(
5555
json_encoder=json,
5656
):
5757
self.json_encoder = json_encoder
58-
super(PayloadJSONBType, self).__init__()
58+
super().__init__()
5959

6060
# serialize
6161
def bind_processor(self, dialect):

model/model_training/losses.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class CrossEntropyLoss(nn.CrossEntropyLoss):
77
def __init__(self, weight=None, size_average=None, ignore_index=-100, reduce=None, reduction="mean"):
8-
super(CrossEntropyLoss, self).__init__(weight, size_average, ignore_index, reduce, reduction)
8+
super().__init__(weight, size_average, ignore_index, reduce, reduction)
99

1010
def forward(self, input, target, mask=None):
1111
if mask is not None:
@@ -14,12 +14,12 @@ def forward(self, input, target, mask=None):
1414
target = target.view(-1)
1515
input = input[mask]
1616
target = target[mask]
17-
return super(CrossEntropyLoss, self).forward(input, target)
17+
return super().forward(input, target)
1818

1919

2020
class PolyLoss(nn.Module):
2121
def __init__(self, weight=None, size_average=None, ignore_index=-100, reduce=None, reduction="mean", epsilon=1.0):
22-
super(PolyLoss, self).__init__()
22+
super().__init__()
2323
self.weight = torch.tensor(weight)
2424
self.ignore_index = ignore_index
2525
self.reduction = reduction

openassistant/templates/prepare.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import typer
22

3+
34
def main(output_dir: str = "data"):
45
"""Download and prepare the dataset for use."""
56
raise NotImplementedError
67

8+
79
if __name__ == "__main__":
8-
typer.run(main)
10+
typer.run(main)

scripts/frontend-development/find-missing-locales.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def get_not_translated(en_json, translation_json, parent_key=None):
1212
not_translated = []
1313
for key in en_json.keys():
1414
if key in translation_json and translation_json[key] == en_json[key]:
15-
not_translated.append(("{0}.{1}".format(parent_key, key) if parent_key else key))
15+
not_translated.append((f"{parent_key}.{key}" if parent_key else key))
1616
elif isinstance(en_json[key], dict):
1717
if key not in translation_json:
1818
msg = f"{parent_key}.{key} (and children)" if parent_key else "{key} (and children)"
@@ -28,12 +28,10 @@ def get_missing(en_json, translation_json):
2828

2929
def print_result(missing, not_translated, file):
3030
if len(missing):
31-
print("[{0}] - {1}\tmissing: {2}".format(path.basename(path.dirname(file)), path.basename(file), missing))
31+
print(f"[{path.basename(path.dirname(file))}] - {path.basename(file)}\tmissing: {missing}")
3232
if len(not_translated):
3333
print(
34-
"[{0}] - {1}\tpotentially untranslated: {2}".format(
35-
path.basename(path.dirname(file)), path.basename(file), not_translated
36-
)
34+
f"[{path.basename(path.dirname(file))}] - {path.basename(file)}\tpotentially untranslated: {not_translated}"
3735
)
3836

3937

website/public/locales/de/message.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"submit_labels": "Absenden",
1717
"tree_stopped": "Tree stopped {{id}}",
1818
"view_user": "Benutzer anzeigen",
19-
"your_recent_messages": "Ihre kürzliche Nachrichten"
19+
"your_recent_messages": "Ihre kürzlichen Nachrichten"
2020
}

0 commit comments

Comments
 (0)