Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Proposal: Support Class-Based Syntax for Python Entities

Aperta
#278 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

La issue non indica alcun file o test. Inizia esaminando la gestione delle entity basata su funzioni esistente intorno a DurableEntityContext e l’esempio TypeScript collegato, quindi determina come i metodi di classe, l’inizializzazione, i risultati restituiti e lo stato persistito dovrebbero corrispondere all’attuale modello delle entity. Il lavoro richiede che, prima dell’implementazione, sia definito un design condiviso per la sintassi e la gestione dello stato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
Python
Stelle
157
Fork
70
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Azure/azure-functions-durable-python

Tutte le issue di Azure/azure-functions-durable-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.