pyscg-0051 should use a context manager

オープン 初心者向け
#1 コメント 4 件 リアクション 0 件 担当者 1 名 GitHub で見る

@s19110 がすでに取り組んでいます。

2026年11月6日 から。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
68/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
security

調査の方向性

リポジトリ内でpyscg-0051のガイダンスと、それに準拠したコード例を見つけてください。前後のルールを読み、リソースの扱いがどのように示されているかを確認してください。issueのコンテキストマネージャーの例が意図する方向を示しています。例外が発生した場合にリソースが解放されるようガイダンスを更新し、改訂した例と説明がその動作に合致していることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

bug

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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ossf/python-secure-coding-guide のほかの issue

ossf/python-secure-coding-guide の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。