chore: refurbish Python code by applying refurb linter rules (#8296)

This commit is contained in:
Bowen Liang
2024-09-12 15:50:49 +08:00
committed by GitHub
parent c69f5b07ba
commit 40fb4d16ef
105 changed files with 220 additions and 276 deletions

View File

@@ -1,6 +1,7 @@
import os
import shutil
from collections.abc import Generator
from pathlib import Path
from flask import Flask
@@ -26,8 +27,7 @@ class LocalStorage(BaseStorage):
folder = os.path.dirname(filename)
os.makedirs(folder, exist_ok=True)
with open(os.path.join(os.getcwd(), filename), "wb") as f:
f.write(data)
Path(os.path.join(os.getcwd(), filename)).write_bytes(data)
def load_once(self, filename: str) -> bytes:
if not self.folder or self.folder.endswith("/"):
@@ -38,9 +38,7 @@ class LocalStorage(BaseStorage):
if not os.path.exists(filename):
raise FileNotFoundError("File not found")
with open(filename, "rb") as f:
data = f.read()
data = Path(filename).read_bytes()
return data
def load_stream(self, filename: str) -> Generator: