pyscg-0051 should use a context manager
@s19110 がすでに取り組んでいます。
2026年11月6日 から。
評価
調査の方向性
リポジトリ内でpyscg-0051のガイダンスと、それに準拠したコード例を見つけてください。前後のルールを読み、リソースの扱いがどのように示されているかを確認してください。issueのコンテキストマネージャーの例が意図する方向を示しています。例外が発生した場合にリソースが解放されるようガイダンスを更新し、改訂した例と説明がその動作に合致していることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
pyscg-0051 compliant solution will not release the resources if there is an exception between the resource creation and release. Most libraries (sqlalchemy, aiohttp, requests) uses context manager for that
for example:
"""Compliant Code Example"""
from contextlib import contextmanager
@contextmanager
def resource_pool():
pool = []
def append_resource(name):
print(f"Allocating resource {name}")
pool.append({"name": name, "active": True}) # Simulated resource
try:
yield pool, append_resource
finally:
# Properly release resources on exit
for resource in pool:
resource["active"] = False
pool.clear()
with resource_pool() as (my_list, append_resource):
append_resource("A")
append_resource("B")
# Outside the context, resources are released
if not any(resource["active"] for resource in my_list):
print("All resources released.")
- 主要言語
- Python
- スター
- 2
- フォーク
- 2
- 平均マージ
- 11分
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ossf/python-secure-coding-guide のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
ossf/python-secure-coding-guide#29 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
-
pysg-0023 Compact version of https://github.com/ossf/python-secure-coding-guide/pull/22/changesオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 58/100
ossf/python-secure-coding-guide の issue をすべて見る
似ている issue
-
documentation type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
add entry to blockオープン
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
StevenBlack/hosts#3299 ·
-
`garak --report` overwrites the input report when its name has no ".report"対応中かも @0z5a が今日担当しました。 オープンneeds-triage
難易度 2/5 半日 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
trace: Pi's 1-hour cache writes are priced at 1.25x, but billed at 2x対応中かも @Shizoqua が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
microsoft/TokenEconomizer#221 ·
メンテナーはふだん 1 日以内に返信
-
plot_graph crashes when a mesh node has no m2m edge対応中かも @tygvi が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
mllam/neural-lam#883 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信