Skip to content

Commit 9b9a891

Browse files
committed
Refactoring. webserver__cherrypy__examples/. Adding the None annotation to the return value
1 parent 002263e commit 9b9a891

20 files changed

Lines changed: 53 additions & 52 deletions

‎webserver__cherrypy__examples/ajax_json.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
class Root(object):
1414
@cherrypy.expose
1515
@cherrypy.tools.json_in()
16-
def update(self):
16+
def update(self) -> str:
1717
input_json = cherrypy.request.json
1818
print("input_json:", input_json)
1919
# do_something_with(input_json)
2020

2121
return "Updated %r." % (input_json,)
2222

2323
@cherrypy.expose
24-
def index(self):
24+
def index(self) -> str:
2525
return """
2626
<html>
2727
<head>

‎webserver__cherrypy__examples/all_exception_handler.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class Root:
13-
def __init__(self):
13+
def __init__(self) -> None:
1414
# Set a custom response for errors.
1515
self._cp_config = {"error_page.default": Root.all_exception_handler}
1616
# # OR:
@@ -19,15 +19,15 @@ def __init__(self):
1919
# Expose the index method through the web. CherryPy will never
2020
# publish methods that don't have the exposed attribute set to True.
2121
@cherrypy.expose
22-
def index(self):
22+
def index(self) -> str:
2323
# CherryPy will call this method for the root URI ("/") and send
2424
# its return value to the client. Because this is tutorial
2525
# lesson number 01, we'll just send something really simple.
2626
# How about...
2727
return 'Hello world!<br><a href="/error">Get error</a>'
2828

2929
@cherrypy.expose
30-
def error(self):
30+
def error(self) -> str:
3131
_ = 1 / 0
3232

3333
return "Bad!"

‎webserver__cherrypy__examples/all_exception_handler__2.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class Root:
3232
# Expose the index method through the web. CherryPy will never
3333
# publish methods that don't have the exposed attribute set to True.
3434
@cherrypy.expose
35-
def index(self):
35+
def index(self) -> str:
3636
# CherryPy will call this method for the root URI ("/") and send
3737
# its return value to the client. Because this is tutorial
3838
# lesson number 01, we'll just send something really simple.
3939
# How about...
4040
return 'Hello world!<br><a href="/error">Get error</a>'
4141

4242
@cherrypy.expose
43-
def error(self):
43+
def error(self) -> str:
4444
_ = 1 / 0
4545

4646
return "Bad!"

‎webserver__cherrypy__examples/arguments.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class HelloWorld:
1515

1616
# NOTE: try http://127.0.0.1:9090/?a=1&b=2&c=123
1717
@cherrypy.expose
18-
def index(self, **kwargs):
18+
def index(self, **kwargs) -> str:
1919
return f"Hello world!: {kwargs}"
2020

2121

‎webserver__cherrypy__examples/autoreload_off.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class HelloWorld:
1313
# Expose the index method through the web. CherryPy will never
1414
# publish methods that don't have the exposed attribute set to True.
1515
@cherrypy.expose
16-
def index(self):
16+
def index(self) -> str:
1717
# CherryPy will call this method for the root URI ("/") and send
1818
# its return value to the client. Because this is tutorial
1919
# lesson number 01, we'll just send something really simple.

‎webserver__cherrypy__examples/complex_site.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class HomePage:
1515
@cherrypy.expose
16-
def index(self):
16+
def index(self) -> str:
1717
return """
1818
<p>Hi, this is the home page! Check out the other
1919
fun stuff on this site:</p>
@@ -25,22 +25,22 @@ def index(self):
2525

2626
class JokePage:
2727
@cherrypy.expose
28-
def index(self):
28+
def index(self) -> str:
2929
return """
3030
<p>"In Python, how do you create a string of random
3131
characters?" -- "Read a Perl file!"</p>
3232
<p>[<a href="../">Return</a>]</p>"""
3333

3434

3535
class LinksPage:
36-
def __init__(self):
36+
def __init__(self) -> None:
3737
# Request handler objects can create their own nested request
3838
# handler objects. Simply create them inside their __init__
3939
# methods!
4040
self.extra = ExtraLinksPage()
4141

4242
@cherrypy.expose
43-
def index(self):
43+
def index(self) -> str:
4444
# Note the way we link to the extra links page (and back).
4545
# As you can see, this object doesn't really care about its
4646
# absolute position in the site tree, since we use relative
@@ -63,7 +63,7 @@ def index(self):
6363

6464
class ExtraLinksPage:
6565
@cherrypy.expose
66-
def index(self):
66+
def index(self) -> str:
6767
# Note the relative link back to the Links page!
6868
return """
6969
<p>Here are some extra useful links:</p>

‎webserver__cherrypy__examples/default_method__uri.py‎

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

2323
class UsersPage:
2424
@cherrypy.expose
25-
def index(self):
25+
def index(self) -> str:
2626
# Since this is just a stupid little example, we'll simply
2727
# display a list of links to random, made-up users. In a real
2828
# application, this could be generated from a database result set.
@@ -33,7 +33,7 @@ def index(self):
3333
"""
3434

3535
@cherrypy.expose
36-
def default(self, user):
36+
def default(self, user) -> str:
3737
# Here we react depending on the virtualPath -- the part of the
3838
# path that could not be mapped to an object method. In a real
3939
# application, we would probably do some database lookups here

‎webserver__cherrypy__examples/expose_methods.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
class HelloWorld:
1414
@cherrypy.expose
15-
def index(self):
15+
def index(self) -> str:
1616
# Let's link to another method here.
1717
return 'We have an <a href="show_msg">important message</a> for you!'
1818

1919
@cherrypy.expose
20-
def show_msg(self):
20+
def show_msg(self) -> str:
2121
# Here's the important message!
2222
return "Hello world!"
2323

‎webserver__cherrypy__examples/files/main.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
class FileDemo(object):
4848
@cherrypy.expose
49-
def index(self):
49+
def index(self) -> str:
5050
return """
5151
<html><body>
5252
<h2>Upload a file</h2>
@@ -60,7 +60,7 @@ def index(self):
6060
"""
6161

6262
@cherrypy.expose
63-
def upload(self, myFile):
63+
def upload(self, myFile) -> str:
6464
out = """<html>
6565
<body>
6666
myFile length: %s<br />

‎webserver__cherrypy__examples/generators_and_yield.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515

1616
class GeneratorDemo:
17-
def header(self):
17+
def header(self) -> str:
1818
return "<html><body><h2>Generators rule!</h2>"
1919

20-
def footer(self):
20+
def footer(self) -> str:
2121
return "</body></html>"
2222

2323
@cherrypy.expose

0 commit comments

Comments
 (0)