Repository: falconry/falcon
Pull request #1805 (2020-12-12 20:42:18)

refactor: rename middlewares to middleware

codecov[bot]: # [Codecov](https://codecov.io/gh/falconry/falcon/pull/1805?src=pr&el=h1) Report
> Merging [#1805](https://codecov.io/gh/falconry/falcon/pull/1805?src=pr&el=desc) (73c178a) into [master](https://codecov.io/gh/falconry/falcon/commit/9f5d1107e4ba6024b266d5214f4fb4eb7a15e494?el=desc) (9f5d110) will **decrease** coverage by `38.10%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/falconry/falcon/pull/1805/graphs/tree.svg?width=650&height=150&src=pr&token=zOtkfNQ3h6)](https://codecov.io/gh/falconry/falcon/pull/1805?src=pr&el=tree)

```diff
@@             Coverage Diff              @@
##            master    #1805       +/-   ##
============================================
- Coverage   100.00%   61.89%   -38.11%     
============================================
  Files           54       54               
  Lines         5076     5076               
  Branches       808      808               
============================================
- Hits          5076     3142     -1934     
- Misses           0     1924     +1924     
- Partials         0       10       +10     
```


| [Impacted Files](https://codecov.io/gh/falconry/falcon/pull/1805?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [falcon/middleware.py](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree#diff-ZmFsY29uL21pZGRsZXdhcmUucHk=) | `97.87% <ø> (ø)` | |
| [falcon/inspect.py](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree#diff-ZmFsY29uL2luc3BlY3QucHk=) | `99.70% <100.00%> (-0.30%)` | :arrow_down: |
| [falcon/asgi/ws.py](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree#diff-ZmFsY29uL2FzZ2kvd3MucHk=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [falcon/asgi/app.py](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree#diff-ZmFsY29uL2FzZ2kvYXBwLnB5) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [falcon/asgi/reader.py](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree#diff-ZmFsY29uL2FzZ2kvcmVhZGVyLnB5) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [falcon/asgi/stream.py](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree#diff-ZmFsY29uL2FzZ2kvc3RyZWFtLnB5) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [falcon/asgi/request.py](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree#diff-ZmFsY29uL2FzZ2kvcmVxdWVzdC5weQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [falcon/asgi/response.py](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree#diff-ZmFsY29uL2FzZ2kvcmVzcG9uc2UucHk=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [falcon/asgi/multipart.py](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree#diff-ZmFsY29uL2FzZ2kvbXVsdGlwYXJ0LnB5) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [falcon/asgi/structures.py](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree#diff-ZmFsY29uL2FzZ2kvc3RydWN0dXJlcy5weQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| ... and [27 more](https://codecov.io/gh/falconry/falcon/pull/1805/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/falconry/falcon/pull/1805?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/falconry/falcon/pull/1805?src=pr&el=footer). Last update [9f5d110...73c178a](https://codecov.io/gh/falconry/falcon/pull/1805?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/docs/_newsfragments/1435.newandimproved.rst b/docs/_newsfragments/1435.newandimproved.rst
index 130edd9..51e273b 100644
--- a/docs/_newsfragments/1435.newandimproved.rst
+++ b/docs/_newsfragments/1435.newandimproved.rst
@@ -1,3 +1,3 @@
 Added inspect module to collect information about an application regarding
-the registered routes, middlewares, static routes, sinks and error handlers
-(See also: :ref:`inspect`.)
\ No newline at end of file
+the registered routes, middleware, static routes, sinks and error handlers
+(See also: :ref:`inspect`.)
diff --git a/docs/api/inspect.rst b/docs/api/inspect.rst
index fbeae71..48cbfae 100644
--- a/docs/api/inspect.rst
+++ b/docs/api/inspect.rst
@@ -111,7 +111,7 @@ This module defines the following inspect functions.
 
 .. autofunction:: falcon.inspect.inspect_routes
 
-.. autofunction:: falcon.inspect.inspect_middlewares
+.. autofunction:: falcon.inspect.inspect_middleware
 
 .. autofunction:: falcon.inspect.inspect_static_routes
 
diff --git a/falcon/__init__.py b/falcon/__init__.py
index 0596ab4..75cf1b0 100644
--- a/falcon/__init__.py
+++ b/falcon/__init__.py
@@ -36,7 +36,7 @@ from falcon.errors import *  # NOQA
 from falcon.redirects import *  # NOQA
 from falcon.http_error import HTTPError  # NOQA
 from falcon.http_status import HTTPStatus  # NOQA
-from falcon.middlewares import CORSMiddleware  # NOQA
+from falcon.middleware import CORSMiddleware  # NOQA
 
 # NOTE(kgriffs): Ensure that "from falcon import uri" will import
 # the same front-door module as "import falcon.uri". This works by
diff --git a/falcon/app.py b/falcon/app.py
index 351aeb3..1401173 100644
--- a/falcon/app.py
+++ b/falcon/app.py
@@ -24,7 +24,7 @@ import falcon.constants
 from falcon.errors import HTTPBadRequest
 from falcon.http_error import HTTPError
 from falcon.http_status import HTTPStatus
-from falcon.middlewares import CORSMiddleware
+from falcon.middleware import CORSMiddleware
 from falcon.request import Request, RequestOptions
 import falcon.responders
 from falcon.response import Response, ResponseOptions
diff --git a/falcon/inspect.py b/falcon/inspect.py
index 7901bc9..df17285 100644
--- a/falcon/inspect.py
+++ b/falcon/inspect.py
@@ -37,7 +37,7 @@ def inspect_app(app: App) -> 'AppInfo':
     static = inspect_static_routes(app)
     sinks = inspect_sinks(app)
     error_handlers = inspect_error_handlers(app)
-    middleware = inspect_middlewares(app)
+    middleware = inspect_middleware(app)
     return AppInfo(routes, middleware, static, sinks, error_handlers, app._ASGI)
 
 
@@ -152,7 +152,7 @@ def inspect_error_handlers(app: App) -> 'List[ErrorHandlerInfo]':
     return errors
 
 
-def inspect_middlewares(app: App) -> 'MiddlewareInfo':
+def inspect_middleware(app: App) -> 'MiddlewareInfo':
     """Inspects the middleware components of an application.
 
     Args:
@@ -702,7 +702,7 @@ class StringVisitor(InspectVisitor):
             m_text = '\n'.join(self.process(m) for m in middleware.middleware_classes)
             self.indent -= 4
             if m_text:
-                text += '\n{}- Middlewares classes:\n{}'.format(self.tab, m_text)
+                text += '\n{}- Middleware classes:\n{}'.format(self.tab, m_text)
 
         return text
 


Test patch:
diff --git a/falcon/middlewares.py b/falcon/middleware.py
similarity index 100%
rename from falcon/middlewares.py
rename to falcon/middleware.py
diff --git a/tests/test_inspect.py b/tests/test_inspect.py
index 92b396e..575547b 100644
--- a/tests/test_inspect.py
+++ b/tests/test_inspect.py
@@ -70,7 +70,7 @@ class TestInspectApp:
         assert len(ai.error_handlers) == 4 if asgi else 3
         assert ai.asgi is asgi
 
-    def test_dependent_middlewares(self, asgi):
+    def test_dependent_middleware(self, asgi):
         app = get_app(asgi, cors=False, independent_middleware=False)
         ai = inspect.inspect_app(app)
         assert ai.middleware.independent is False
@@ -165,7 +165,7 @@ class TestInspectApp:
             assert eh.error in ('WebSocketDisconnected', 'Exception', 'HTTPStatus', 'HTTPError')
 
     def test_middleware(self, asgi):
-        mi = inspect.inspect_middlewares(make_app_async() if asgi else make_app())
+        mi = inspect.inspect_middleware(make_app_async() if asgi else make_app())
 
         def test(m, cn, ml, inte):
             assert isinstance(m, inspect.MiddlewareClassInfo)
@@ -203,7 +203,7 @@ class TestInspectApp:
         )
 
     def test_middleware_tree(self, asgi):
-        mi = inspect.inspect_middlewares(make_app_async() if asgi else make_app())
+        mi = inspect.inspect_middleware(make_app_async() if asgi else make_app())
 
         def test(tl, names, cls):
             for (t, n, c) in zip(tl, names, cls):
@@ -436,19 +436,19 @@ class TestStringVisitor:
 
     def test_middleware_method(self, internal):
         sv = inspect.StringVisitor(False, internal)
-        mm = inspect.inspect_middlewares(make_app()).middleware_classes[0].methods[0]
+        mm = inspect.inspect_middleware(make_app()).middleware_classes[0].methods[0]
 
         assert sv.process(mm) == '{0.function_name}'.format(mm)
 
     def test_middleware_method_verbose(self, internal):
         sv = inspect.StringVisitor(True, internal)
-        mm = inspect.inspect_middlewares(make_app()).middleware_classes[0].methods[0]
+        mm = inspect.inspect_middleware(make_app()).middleware_classes[0].methods[0]
 
         assert sv.process(mm) == '{0.function_name} ({0.source_info})'.format(mm)
 
     def test_middleware_class(self, internal):
         sv = inspect.StringVisitor(False, internal)
-        mc = inspect.inspect_middlewares(make_app()).middleware_classes[0]
+        mc = inspect.inspect_middleware(make_app()).middleware_classes[0]
 
         mml = ['   ├── {}'.format(sv.process(m)) for m in mc.methods][:-1]
         mml += ['   └── {}'.format(sv.process(m)) for m in mc.methods][-1:]
@@ -458,7 +458,7 @@ class TestStringVisitor:
 
     def test_middleware_class_verbose(self, internal):
         sv = inspect.StringVisitor(True, internal)
-        mc = inspect.inspect_middlewares(make_app()).middleware_classes[0]
+        mc = inspect.inspect_middleware(make_app()).middleware_classes[0]
 
         mml = ['   ├── {}'.format(sv.process(m)) for m in mc.methods][:-1]
         mml += ['   └── {}'.format(sv.process(m)) for m in mc.methods][-1:]
@@ -468,7 +468,7 @@ class TestStringVisitor:
 
     def test_middleware_class_no_methods(self, internal):
         sv = inspect.StringVisitor(False, internal)
-        mc = inspect.inspect_middlewares(make_app()).middleware_classes[0]
+        mc = inspect.inspect_middleware(make_app()).middleware_classes[0]
         mc.methods.clear()
         exp = '↣ {0.name}'.format(mc)
         assert sv.process(mc) == exp
@@ -476,14 +476,14 @@ class TestStringVisitor:
     @pytest.mark.parametrize('verbose', (True, False))
     def test_middleware_tree_item(self, verbose, internal):
         sv = inspect.StringVisitor(verbose, internal)
-        mt = inspect.inspect_middlewares(make_app()).middleware_tree
+        mt = inspect.inspect_middleware(make_app()).middleware_tree
         for r, s in ((mt.request[0], '→'), (mt.resource[0], '↣'), (mt.response[0], '↢')):
             assert sv.process(r) == '{0} {1.class_name}.{1.name}'.format(s, r)
 
     @pytest.mark.parametrize('verbose', (True, False))
     def test_middleware_tree(self, verbose, internal):
         sv = inspect.StringVisitor(verbose, internal)
-        mt = inspect.inspect_middlewares(make_app()).middleware_tree
+        mt = inspect.inspect_middleware(make_app()).middleware_tree
         lines = []
         space = ''
         for r in mt.request:
@@ -504,7 +504,7 @@ class TestStringVisitor:
 
     def test_middleware_tree_response_only(self, internal):
         sv = inspect.StringVisitor(False, internal)
-        mt = inspect.inspect_middlewares(make_app()).middleware_tree
+        mt = inspect.inspect_middleware(make_app()).middleware_tree
         mt.request.clear()
         mt.resource.clear()
         lines = []
@@ -520,7 +520,7 @@ class TestStringVisitor:
 
     def test_middleware_tree_no_response(self, internal):
         sv = inspect.StringVisitor(False, internal)
-        mt = inspect.inspect_middlewares(make_app()).middleware_tree
+        mt = inspect.inspect_middleware(make_app()).middleware_tree
         mt.response.clear()
         lines = []
         space = ''
@@ -538,7 +538,7 @@ class TestStringVisitor:
 
     def test_middleware_tree_no_resource(self, internal):
         sv = inspect.StringVisitor(False, internal)
-        mt = inspect.inspect_middlewares(make_app()).middleware_tree
+        mt = inspect.inspect_middleware(make_app()).middleware_tree
         mt.resource.clear()
         lines = []
         space = '  '
@@ -556,18 +556,18 @@ class TestStringVisitor:
 
     def test_middleware(self, internal):
         sv = inspect.StringVisitor(False, internal)
-        m = inspect.inspect_middlewares(make_app())
+        m = inspect.inspect_middleware(make_app())
 
         assert sv.process(m) == sv.process(m.middleware_tree)
 
     def test_middleware_verbose(self, internal):
         sv = inspect.StringVisitor(True, internal)
-        m = inspect.inspect_middlewares(make_app())
+        m = inspect.inspect_middleware(make_app())
 
         mt = sv.process(m.middleware_tree)
         sv.indent += 4
         mc = '\n'.join(sv.process(cls) for cls in m.middleware_classes)
-        exp = '{}\n- Middlewares classes:\n{}'.format(mt, mc)
+        exp = '{}\n- Middleware classes:\n{}'.format(mt, mc)
         assert inspect.StringVisitor(True).process(m) == exp
 
     def make(self, sv, app, v, i, r=True, m=True, sr=True, s=True, e=True):