This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from zopefoundation/patrick-annotation-fix
Make function annotations in route handlers work
- Loading branch information
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
27 changes: 27 additions & 0 deletions
27
bobodoctestumentation/src/bobodoctestumentation/annotations.test
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
==================== | ||
Function Annotations | ||
==================== | ||
|
||
There was a bug that would cause things to break when using Python 3 | ||
function annotations in a route handler. In the future, we could use | ||
annotations to perform automatic type conversion, but for now we're just | ||
demonstrating that simply using annotations no longer breaks things. | ||
|
||
.. code-block:: python | ||
|
||
import bobo | ||
import bobo.testmodule1 | ||
import webtest | ||
|
||
@bobo.get("/foo/:bar/:baz") | ||
def foo(bobo_request, bar:"bar", baz:"baz"): | ||
return "OK" | ||
|
||
bobo.testmodule1.foo = foo | ||
app = webtest.TestApp( | ||
bobo.Application(bobo_resources='bobo.testmodule1')) | ||
|
||
We get back the exepcted result when making a request to this route: | ||
|
||
>>> app.get("/foo/1/2") | ||
<200 OK text/html body=b'OK'> |
This file contains 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