Skip to content

Commit

Permalink
Upgrade Python syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
dokterbob committed Nov 19, 2024
1 parent 0c1104e commit 094786b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions backend/chainlit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def init_config(log=False):
dst = os.path.join(config_translation_dir, file)
if not os.path.exists(dst):
src = os.path.join(TRANSLATIONS_DIR, file)
with open(src, "r", encoding="utf-8") as f:
with open(src, encoding="utf-8") as f:
translation = json.load(f)
with open(dst, "w", encoding="utf-8") as f:
json.dump(translation, f, indent=4)
Expand Down Expand Up @@ -515,15 +515,15 @@ def load_config():
def lint_translations():
# Load the ground truth (en-US.json file from chainlit source code)
src = os.path.join(TRANSLATIONS_DIR, "en-US.json")
with open(src, "r", encoding="utf-8") as f:
with open(src, encoding="utf-8") as f:
truth = json.load(f)

# Find the local app translations
for file in os.listdir(config_translation_dir):
if file.endswith(".json"):
# Load the translation file
to_lint = os.path.join(config_translation_dir, file)
with open(to_lint, "r", encoding="utf-8") as f:
with open(to_lint, encoding="utf-8") as f:
translation = json.load(f)

# Lint the translation file
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/data/sql_alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async def _get_user_id_by_thread(self, thread_id: str) -> Optional[str]:
async def create_user(self, user: User) -> Optional[PersistedUser]:
if self.show_logger:
logger.info(f"SQLAlchemy: create_user, user_identifier={user.identifier}")
existing_user: Optional["PersistedUser"] = await self.get_user(user.identifier)
existing_user: Optional[PersistedUser] = await self.get_user(user.identifier)
user_dict: Dict[str, Any] = {
"identifier": str(user.identifier),
"metadata": json.dumps(user.metadata) or {},
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async def send_ask_user(
await self.task_end()

final_res: Optional[
Union["StepDict", "AskActionResponse", List["FileDict"]]
Union[StepDict, AskActionResponse, List[FileDict]]
] = None

if user_res:
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/langchain/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ async def _start_trace(self, run: Run) -> None:
if ignore:
return

step_type: "TrueStepType" = "undefined"
step_type: TrueStepType = "undefined"
if run.run_type == "agent":
step_type = "run"
elif run.run_type == "chain":
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@


def random_secret(length: int = 64):
return "".join((secrets.choice(chars) for i in range(length)))
return "".join(secrets.choice(chars) for i in range(length))
2 changes: 1 addition & 1 deletion backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def get_html_template():

index_html_file_path = os.path.join(build_dir, "index.html")

with open(index_html_file_path, "r", encoding="utf-8") as f:
with open(index_html_file_path, encoding="utf-8") as f:
content = f.read()
content = content.replace(PLACEHOLDER, tags)
if js:
Expand Down
4 changes: 2 additions & 2 deletions backend/chainlit/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@


class JSONEncoderIgnoreNonSerializable(json.JSONEncoder):
def default(self, obj):
def default(self, o):
try:
return super(JSONEncoderIgnoreNonSerializable, self).default(obj)
return super().default(o)
except TypeError:
return None

Expand Down
4 changes: 2 additions & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ target-version = "py39"
line-length = 120

[tool.ruff.lint]
select = ["E", "F", "I", "LOG"]
ignore = ["E712", "E501"]
select = ["E", "F", "I", "LOG", "UP"]
ignore = ["E712", "E501", "UP006", "UP035"]

[tool.ruff.lint.isort]
combine-as-imports = true

0 comments on commit 094786b

Please sign in to comment.