Skip to content

Commit e108bf3

Browse files
committed
[Chore]
Reformat file: typehint, renamed `database.py` file.
1 parent 58a25bc commit e108bf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+225
-259
lines changed

ch01/todos/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
@app.get("/")
7-
async def welcome():
7+
async def welcome() -> dict:
88
return {
99
"message": "Hello World"
1010
}

ch02/todos/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from fastapi import FastAPI
2+
23
from todo import todo_router
34

45
app = FastAPI()
56

67

78
@app.get("/")
8-
async def welcome():
9+
async def welcome() -> dict:
910
return {
1011
"message": "Hello World"
1112
}
1213

13-
app.include_router(todo_router)
14+
15+
app.include_router(todo_router)

ch02/todos/todo.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from fastapi import APIRouter, Path
2+
23
from model import Todo, TodoItem
34

45
todo_router = APIRouter()
@@ -7,22 +8,22 @@
78

89

910
@todo_router.post("/todo")
10-
async def add_todo(todo: Todo):
11+
async def add_todo(todo: Todo) -> dict:
1112
todo_list.append(todo)
1213
return {
1314
"message": "Todo added successfully."
1415
}
1516

1617

1718
@todo_router.get("/todo")
18-
async def retrieve_todo():
19+
async def retrieve_todo() -> dict:
1920
return {
2021
"todos": todo_list
2122
}
2223

2324

2425
@todo_router.get("/todo/{todo_id}")
25-
async def get_single_todo(todo_id: int = Path(..., title="The ID of the todo to retrieve.")):
26+
async def get_single_todo(todo_id: int = Path(..., title="The ID of the todo to retrieve.")) -> dict:
2627
for todo in todo_list:
2728
if todo.id == todo_id:
2829
return {
@@ -34,7 +35,7 @@ async def get_single_todo(todo_id: int = Path(..., title="The ID of the todo to
3435

3536

3637
@todo_router.put("/todo/{todo_id}")
37-
async def update_todo(todo_data: TodoItem, todo_id: int = Path(..., title="The ID of the todo to be updated.")):
38+
async def update_todo(todo_data: TodoItem, todo_id: int = Path(..., title="The ID of the todo to be updated.")) -> dict:
3839
for todo in todo_list:
3940
if todo.id == todo_id:
4041
todo.item = todo_data.item
@@ -47,7 +48,7 @@ async def update_todo(todo_data: TodoItem, todo_id: int = Path(..., title="The I
4748

4849

4950
@todo_router.delete("/todo/{todo_id}")
50-
async def delete_single_todo(todo_id: int):
51+
async def delete_single_todo(todo_id: int) -> dict:
5152
for index in range(len(todo_list)):
5253
todo = todo_list[index]
5354
if todo.id == todo_id:
@@ -61,7 +62,7 @@ async def delete_single_todo(todo_id: int):
6162

6263

6364
@todo_router.delete("/todo")
64-
async def delete_all_todo():
65+
async def delete_all_todo() -> dict:
6566
todo_list.clear()
6667
return {
6768
"message": "Todos deleted successfully."

ch03/todos/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from fastapi import FastAPI
2+
23
from todo import todo_router
34

45
app = FastAPI()
56

67

78
@app.get("/")
8-
async def welcome():
9+
async def welcome() -> dict:
910
return {
1011
"message": "Hello World"
1112
}
1213

13-
app.include_router(todo_router)
14+
15+
app.include_router(todo_router)

ch03/todos/todo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77

88

99
@todo_router.post("/todo", status_code=201)
10-
async def add_todo(todo: Todo):
10+
async def add_todo(todo: Todo) -> dict:
1111
todo_list.append(todo)
1212
return {
1313
"message": "Todo added successfully."
1414
}
1515

1616

1717
@todo_router.get("/todo", response_model=TodoItems)
18-
async def retrieve_todo():
18+
async def retrieve_todo() -> dict:
1919
return {
2020
"todos": todo_list
2121
}
2222

2323

2424
@todo_router.get("/todo/{todo_id}")
25-
async def get_single_todo(todo_id: int = Path(..., title="The ID of the todo to retrieve.")):
25+
async def get_single_todo(todo_id: int = Path(..., title="The ID of the todo to retrieve.")) -> dict:
2626
for todo in todo_list:
2727
if todo.id == todo_id:
2828
return {
@@ -35,7 +35,7 @@ async def get_single_todo(todo_id: int = Path(..., title="The ID of the todo to
3535

3636

3737
@todo_router.put("/todo/{todo_id}")
38-
async def update_todo(todo_data: TodoItem, todo_id: int = Path(..., title="The ID of the todo to be updated.")):
38+
async def update_todo(todo_data: TodoItem, todo_id: int = Path(..., title="The ID of the todo to be updated.")) -> dict:
3939
for todo in todo_list:
4040
if todo.id == todo_id:
4141
todo.item = todo_data.item
@@ -50,7 +50,7 @@ async def update_todo(todo_data: TodoItem, todo_id: int = Path(..., title="The I
5050

5151

5252
@todo_router.delete("/todo/{todo_id}")
53-
async def delete_single_todo(todo_id: int):
53+
async def delete_single_todo(todo_id: int) -> dict:
5454
for index in range(len(todo_list)):
5555
todo = todo_list[index]
5656
if todo.id == todo_id:
@@ -65,7 +65,7 @@ async def delete_single_todo(todo_id: int):
6565

6666

6767
@todo_router.delete("/todo")
68-
async def delete_all_todo():
68+
async def delete_all_todo() -> dict:
6969
todo_list.clear()
7070
return {
7171
"message": "Todos deleted successfully."

ch04/todos/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from fastapi import FastAPI
2+
23
from todo import todo_router
34

45
app = FastAPI()
56

67

78
@app.get("/")
8-
async def welcome():
9+
async def welcome() -> dict:
910
return {
1011
"message": "Hello World"
1112
}
1213

13-
app.include_router(todo_router)
14+
15+
app.include_router(todo_router)

ch04/todos/templates/home.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<meta content="IE=edge" http-equiv="X-UA-Compatible">
6+
<meta content="width=device-width, initial-scale=1.0" name="viewport">
77
<title>Packt Todo Application</title>
8-
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
9-
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
10-
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css"
11-
integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">
8+
<link crossorigin="anonymous" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
9+
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" rel="stylesheet">
10+
<link crossorigin="anonymous" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css"
11+
integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" rel="stylesheet">
1212
</head>
1313
<body>
1414
<header>

ch04/todos/templates/todo.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<form method="post">
99
<div class="col-auto">
1010
<div class="input-group mb-3">
11-
<input type="text" name="item" value="{{ item }}" class="form-control"
12-
placeholder="Purchase Packt's Python workshop course" aria-label="Add a todo"
13-
aria-describedby="button-addon2"/>
14-
<button class="btn btn-outline-primary" type="submit" id="button-addon2"
15-
data-mdb-ripple-color="dark">
11+
<input aria-describedby="button-addon2" aria-label="Add a todo" class="form-control" name="item"
12+
placeholder="Purchase Packt's Python workshop course" type="text"
13+
value="{{ item }}"/>
14+
<button class="btn btn-outline-primary" data-mdb-ripple-color="dark" id="button-addon2"
15+
type="submit">
1616
Add Todo
1717
</button>
1818
</div>

ch04/todos/todo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def get_single_todo(request: Request, todo_id: int = Path(..., title="The
4545

4646
@todo_router.put("/todo/{todo_id}")
4747
async def update_todo(request: Request, todo_data: TodoItem,
48-
todo_id: int = Path(..., title="The ID of the todo to be updated.")):
48+
todo_id: int = Path(..., title="The ID of the todo to be updated.")) -> dict:
4949
for todo in todo_list:
5050
if todo.id == todo_id:
5151
todo.item = todo_data.item
@@ -60,7 +60,7 @@ async def update_todo(request: Request, todo_data: TodoItem,
6060

6161

6262
@todo_router.delete("/todo/{todo_id}")
63-
async def delete_single_todo(request: Request, todo_id: int):
63+
async def delete_single_todo(request: Request, todo_id: int) -> dict:
6464
for index in range(len(todo_list)):
6565
todo = todo_list[index]
6666
if todo.id == todo_id:
@@ -75,7 +75,7 @@ async def delete_single_todo(request: Request, todo_id: int):
7575

7676

7777
@todo_router.delete("/todo")
78-
async def delete_all_todo():
78+
async def delete_all_todo() -> dict:
7979
todo_list.clear()
8080
return {
8181
"message": "Todos deleted successfully."

ch05/planner/models/users.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pydantic import BaseModel, EmailStr
22

33

4-
54
class User(BaseModel):
65
email: EmailStr
76
password: str
@@ -20,8 +19,8 @@ class UserSignIn(BaseModel):
2019
password: str
2120

2221
schema_extra = {
23-
"example": {
24-
"email": "fastapi@packt.com",
25-
"password": "strong!!!"
26-
}
22+
"example": {
23+
"email": "fastapi@packt.com",
24+
"password": "strong!!!"
2725
}
26+
}

0 commit comments

Comments
 (0)