Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Proposal: Support Class-Based Syntax for Python Entities

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

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
python
領域
backend

調査の方向性

この issue ではファイルやテストが指定されていません。まず DurableEntityContext 周辺の既存の関数ベースの entity 処理と、リンクされた TypeScript の例を確認し、そのうえで、クラスメソッド、初期化、返される結果、永続化された状態を現在の entity モデルにどのように対応付けるべきかを判断してください。完了の条件は、実装前に構文と状態処理の設計について合意されていることです。

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

説明

Enhancement fixed-in-v2

Currently, Entities in Python (and JavaScript) only support function-based syntax, where operations are delineated by a cascade of if-statements. In C#, a class-based syntax is supported, which allows individual operations to be split into methods belonging to a larger class that represents the Entity itself.

Implementing this alternative syntax should not be too difficult, it's mostly just a layer of indirection. Making matters simpler, we already have a community-driven example of how to do this for TypeScript here: https://scale-tone.github.io/2021/03/15/durable-mvc .

As an example for the syntax, consider the following entity function using the current implementation syntax

def entity_function(context: df.DurableEntityContext):
    current_value = context.get_state(lambda: 0)
    operation = context.operation_name
    if operation == "add":
        amount = context.get_input()
        current_value += amount
    elif operation == "reset":
        current_value = 0
    elif operation == "get":
        pass
    
    context.set_state(current_value)
    context.set_result(current_value)

It's class-based syntax alternative would look as follows:

class Counter:
   def __init__(self): # this corresponds to state initializer, or the `lambda: 0` in the function-based syntax
       self.entity_state= 0
 
    def add(self, amount):
        self.entity_state+= amount
        return self.entity_state
    def get(self):
        return self.entity_state
     def reset(self):
        return self.entity_state= 0

Finally, it makes sense to me that the return statement would set the value for context.set_result. A more difficult question is to know what value to save for set_state. One easy solution is to require the state to be under the name self.entity_state but perhaps that's too restrictive. What do others think?

主要言語
Python
スター
157
フォーク
70
PR マージ指標
30日以内にマージされた PR はありません

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

Azure/azure-functions-durable-python のほかの issue

Azure/azure-functions-durable-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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