Improved cross-language homogeneity#34
Merged
knative-prow[bot] merged 1 commit intoknative-extensions:mainfrom Feb 10, 2025
Merged
Improved cross-language homogeneity#34knative-prow[bot] merged 1 commit intoknative-extensions:mainfrom
knative-prow[bot] merged 1 commit intoknative-extensions:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: lkingland The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Use an explicit "handle" method on Function instances, as this is the most similar method signature approach between different language; a primary goal of the project. This is in contrast to a more strict adherence to the ASGI spec which would see the Function object itself be callable. See PR for further exploration of this choice.
0537c09 to
77ea872
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Use an explicit "handle" method on Function instances, as this is the most similar method signature approach between different language; a primary goal of the project. This is in contrast to a more strict adherence to the ASGI spec which would see the Function object itself be callable.
Rationale
Python's call is idiomatically used when the primary purpose of an object is to be callable with a single, well-defined operation. This matches ASGI's design philosophy where handlers are fundamentally single-purpose callables that process requests. However, the Function object also supports additional methods such as readiness/liveness checks, and start/stop event handlers. Furthermore, the cross-language design goal of Functions suggests having a consistent .handle() method instead. This approach has has significant benefits:
It makes the code more immediately understandable across language boundaries by maintaining consistency of supported method signatures
It Better communicates intent
It allows for easier automated code generation or translation
It eases ongoing support burden by minimizing language-specific deviations
It maintains consistent mental models across codebases
It makes it clearer that the object is a "handler" rather than just any callable
Using .handle() is not anti-idiomatic, as many frameworks use this method-based approach rather than making objects callable (e.g., Flask class-based views use .dispatch_request()).
This was the original implementation, and after exploring usage of Python functions as an ASGI callable, it is clear the named
handle()method is better overall. This PR reverts to that approach.