Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Proposal: Support Class-Based Syntax for Python Entities

未关闭
#278 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
python
领域
backend

调研方向

该 issue 没有指定任何文件或测试。首先检查 DurableEntityContext 周围现有的基于函数的实体处理方式以及链接的 TypeScript 示例,然后确定类方法、初始化、返回的结果和持久化状态应如何映射到当前实体模型。完成的前提是在实现之前就语法和状态处理设计达成一致。

由索引模型根据 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 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Azure/azure-functions-durable-python 的其他 Issue

查看 Azure/azure-functions-durable-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。