Skip to content

Improved cross-language homogeneity#34

Merged
knative-prow[bot] merged 1 commit intoknative-extensions:mainfrom
lkingland:handler-method
Feb 10, 2025
Merged

Improved cross-language homogeneity#34
knative-prow[bot] merged 1 commit intoknative-extensions:mainfrom
lkingland:handler-method

Conversation

@lkingland
Copy link
Contributor

@lkingland lkingland commented Feb 10, 2025

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.

@knative-prow
Copy link

knative-prow bot commented Feb 10, 2025

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot requested review from matejvasek and matzew February 10, 2025 03:45
@knative-prow knative-prow bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 10, 2025
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.
@lkingland lkingland added the lgtm Indicates that a PR is ready to be merged. label Feb 10, 2025
@knative-prow knative-prow bot merged commit f065e0b into knative-extensions:main Feb 10, 2025
14 checks passed
@lkingland lkingland deleted the handler-method branch February 10, 2025 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant