Skip to content

Commit

Permalink
Replace view_kwargs.pop with view_kwargs.get
Browse files Browse the repository at this point in the history
  • Loading branch information
luolingchun committed May 31, 2023
1 parent e0a0281 commit d1eda8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions docs/Quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ class BookListAPIView:
*New in v2.4.0*

You can define a parameter named `view_kwargs` (the only parameter of the `__init__` function),
and using `view_kwargs.pop` get the required keys for each.
and using `view_kwargs.get` get the required keys for each.

```python
@api_view.route("/book")
class BookListAPIView:
def __init__(self, view_kwargs=None):
self.a = view_kwargs.pop("a")
self.a = view_kwargs.get("a")

def get(self):
...
Expand All @@ -167,7 +167,7 @@ class BookListAPIView:
@api_view.route("/book/<id>")
class BookAPIView:
def __init__(self, view_kwargs=None):
self.b = view_kwargs.pop("b")
self.b = view_kwargs.get("b")

def get(self):
...
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api_view_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BookPath(BaseModel):
@api_view.route("/book")
class BookListAPIView:
def __init__(self, view_kwargs=None):
self.a = view_kwargs.pop("a")
self.a = view_kwargs.get("a")

@api_view.doc(summary="get book list")
def get(self):
Expand All @@ -31,7 +31,7 @@ def get(self):
@api_view.route("/book/<id>")
class BookAPIView:
def __init__(self, view_kwargs=None):
self.b = view_kwargs.pop("b")
self.b = view_kwargs.get("b")

@api_view.doc(summary="get book list")
def get(self, path: BookPath):
Expand Down

0 comments on commit d1eda8e

Please sign in to comment.