Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Proposal: Support Class-Based Syntax for Python Entities

Đang mở
#278 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Issue không nêu tên tệp hoặc bài kiểm thử nào. Hãy bắt đầu bằng việc xem xét cách xử lý entity dựa trên hàm hiện có quanh DurableEntityContext và ví dụ TypeScript được liên kết, sau đó xác định các phương thức của class, việc khởi tạo, các kết quả được trả về và trạng thái được persist nên ánh xạ như thế nào vào mô hình entity hiện tại. Điều kiện hoàn thành là phải thống nhất được thiết kế về cú pháp và cách xử lý trạng thái trước khi triển khai.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
Python
Star
157
Fork
71
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Azure/azure-functions-durable-python

Tất cả issue của Azure/azure-functions-durable-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.