From 6e38d65459457404e500693f80b96b55f8405418 Mon Sep 17 00:00:00 2001 From: Ryuuji Yoshimoto Date: Sun, 30 Aug 2026 00:40:33 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20codecs.open=20=E3=82=92=E7=B5=84?= =?UTF-8?q?=E3=81=BF=E8=BE=BC=E3=81=BF=E3=81=AE=20open=20=E3=81=B8?= =?UTF-8?q?=E7=BD=AE=E3=81=8D=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit codecs.open は非推奨。組み込みの open に encoding を渡せば済むため codecs のインポートごと削除した。 main.py 側は index.html / jsonschema.json をリクエスト毎に読み直していたのを ndc8/ndc9 データと同じく起動時に一度だけ読み込む形に揃えた (単純に open() へ置き換えただけだと ruff の ASYNC230 「async関数内でのブロッキングI/O」に引っかかりCIが落ちるため)。 Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01JDwuuz1Km2CuC6pAEfHQAN --- main.py | 12 +++++++----- validate.py | 3 +-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 3a637ff..1179a96 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -import codecs import io import json import zipfile @@ -27,6 +26,12 @@ del i['source'] ndc9_items[key] = i +with open('./templates/index.html', encoding='utf-8') as file: + index_html = file.read() + +with open('jsonschema.json', encoding='utf-8') as file: + json_schema = json.load(file) + @app.get( '/', @@ -37,8 +42,7 @@ response_class=HTMLResponse, ) async def index(): - with codecs.open('./templates/index.html', 'r', 'utf-8') as file: - return file.read() + return index_html @app.get( @@ -49,8 +53,6 @@ async def index(): response_description='JSONスキーマを返す', ) async def schema(): - with codecs.open('jsonschema.json', 'r', 'utf-8') as file: - json_schema = json.load(file) return ORJSONResponse(json_schema, headers={'Access-Control-Allow-Origin': '*'}) diff --git a/validate.py b/validate.py index fb1ae24..213bf0f 100644 --- a/validate.py +++ b/validate.py @@ -1,4 +1,3 @@ -import codecs import json import jsonschema @@ -8,7 +7,7 @@ url = 'http://127.0.0.1:8000/ndc9.json' r = requests.get(url, headers={'content-type': 'application/json'}) data = r.json() - with codecs.open('jsonschema.json', 'r', 'utf-8') as file: + with open('jsonschema.json', encoding='utf-8') as file: json_schema = json.load(file) for item in data.values(): jsonschema.validate(item, json_schema)