From 9d9108fe25600c566643f902255d74ff68d88967 Mon Sep 17 00:00:00 2001 From: Kevin Kirsche Date: Tue, 14 Sep 2021 12:29:42 -0400 Subject: [PATCH 1/3] fix: typo docs/debugging.rst:72 docs/debugging.rst:72: controled ==> controlled --- docs/debugging.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/debugging.rst b/docs/debugging.rst index a9f984b4..66118de2 100644 --- a/docs/debugging.rst +++ b/docs/debugging.rst @@ -69,7 +69,7 @@ enables the debugger and reloader. ``FLASK_ENV`` can only be set as an environment variable. When running from Python code, passing ``debug=True`` enables debug mode, which is -mostly equivalent. Debug mode can be controled separately from +mostly equivalent. Debug mode can be controlled separately from ``FLASK_ENV`` with the ``FLASK_DEBUG`` environment variable as well. .. code-block:: python From 6a4bf9eec13e035cf10ecc16e462049b4c967e41 Mon Sep 17 00:00:00 2001 From: David Lord Date: Fri, 1 Oct 2021 09:39:10 -0700 Subject: [PATCH 2/3] use exception chaining fixes flake8-bugbear B904 --- src/flask/app.py | 4 ++-- src/flask/cli.py | 28 ++++++++++++++-------------- src/flask/debughelpers.py | 5 +++-- src/flask/scaffold.py | 2 +- src/flask/signals.py | 2 +- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/flask/app.py b/src/flask/app.py index 301694ac..9097c464 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -1621,7 +1621,7 @@ class Flask(Scaffold): except ImportError: raise RuntimeError( "Install Flask with the 'async' extra in order to use async views." - ) + ) from None # Check that Werkzeug isn't using its fallback ContextVar class. if ContextVar.__module__ == "werkzeug.local": @@ -1727,7 +1727,7 @@ class Flask(Scaffold): " response. The return type must be a string," " dict, tuple, Response instance, or WSGI" f" callable, but it was a {type(rv).__name__}." - ).with_traceback(sys.exc_info()[2]) + ).with_traceback(sys.exc_info()[2]) from None else: raise TypeError( "The view function did not return a valid" diff --git a/src/flask/cli.py b/src/flask/cli.py index 0d101d0a..7ab4fa1c 100644 --- a/src/flask/cli.py +++ b/src/flask/cli.py @@ -69,15 +69,16 @@ def find_best_app(script_info, module): if isinstance(app, Flask): return app - except TypeError: + except TypeError as e: if not _called_with_wrong_args(app_factory): raise + raise NoAppException( f"Detected factory {attr_name!r} in module {module.__name__!r}," " but could not call it without arguments. Use" f" \"FLASK_APP='{module.__name__}:{attr_name}(args)'\"" " to specify arguments." - ) + ) from e raise NoAppException( "Failed to find Flask application or factory in module" @@ -161,7 +162,7 @@ def find_app_by_string(script_info, module, app_name): except SyntaxError: raise NoAppException( f"Failed to parse {app_name!r} as an attribute name or function call." - ) + ) from None if isinstance(expr, ast.Name): name = expr.id @@ -184,7 +185,7 @@ def find_app_by_string(script_info, module, app_name): # message with the full expression instead. raise NoAppException( f"Failed to parse arguments as literal values: {app_name!r}." - ) + ) from None else: raise NoAppException( f"Failed to parse {app_name!r} as an attribute name or function call." @@ -192,17 +193,17 @@ def find_app_by_string(script_info, module, app_name): try: attr = getattr(module, name) - except AttributeError: + except AttributeError as e: raise NoAppException( f"Failed to find attribute {name!r} in {module.__name__!r}." - ) + ) from e # If the attribute is a function, call it with any args and kwargs # to get the real application. if inspect.isfunction(attr): try: app = call_factory(script_info, attr, args, kwargs) - except TypeError: + except TypeError as e: if not _called_with_wrong_args(attr): raise @@ -210,7 +211,7 @@ def find_app_by_string(script_info, module, app_name): f"The factory {app_name!r} in module" f" {module.__name__!r} could not be called with the" " specified arguments." - ) + ) from e else: app = attr @@ -257,16 +258,15 @@ def locate_app(script_info, module_name, app_name, raise_if_not_found=True): try: __import__(module_name) - except ImportError: + except ImportError as e: # Reraise the ImportError if it occurred within the imported module. # Determine this by checking whether the trace has a depth > 1. if sys.exc_info()[2].tb_next: raise NoAppException( - f"While importing {module_name!r}, an ImportError was" - f" raised:\n\n{traceback.format_exc()}" - ) + f"While importing {module_name!r}, an ImportError was raised." + ) from e elif raise_if_not_found: - raise NoAppException(f"Could not import {module_name!r}.") + raise NoAppException(f"Could not import {module_name!r}.") from e else: return @@ -725,7 +725,7 @@ class CertParamType(click.ParamType): "Using ad-hoc certificates requires the cryptography library.", ctx, param, - ) + ) from None return value diff --git a/src/flask/debughelpers.py b/src/flask/debughelpers.py index ce65c487..212f7d7e 100644 --- a/src/flask/debughelpers.py +++ b/src/flask/debughelpers.py @@ -83,10 +83,11 @@ def attach_enctype_error_multidict(request): def __getitem__(self, key): try: return oldcls.__getitem__(self, key) - except KeyError: + except KeyError as e: if key not in request.form: raise - raise DebugFilesKeyError(request, key) + + raise DebugFilesKeyError(request, key) from e newcls.__name__ = oldcls.__name__ newcls.__module__ = oldcls.__module__ diff --git a/src/flask/scaffold.py b/src/flask/scaffold.py index 42eabcfc..07ca5c65 100644 --- a/src/flask/scaffold.py +++ b/src/flask/scaffold.py @@ -715,7 +715,7 @@ class Scaffold: f"'{code_or_exception}' is not a recognized HTTP error" " code. Use a subclass of HTTPException with that code" " instead." - ) + ) from None self.error_handler_spec[None][code][exc_class] = t.cast( "ErrorHandlerCallable[Exception]", f diff --git a/src/flask/signals.py b/src/flask/signals.py index 63667bdb..2c6d6469 100644 --- a/src/flask/signals.py +++ b/src/flask/signals.py @@ -29,7 +29,7 @@ except ImportError: raise RuntimeError( "Signalling support is unavailable because the blinker" " library is not installed." - ) + ) from None connect = connect_via = connected_to = temporarily_connected_to = _fail disconnect = _fail From 42a6da2da38af65a0f097bb88e3e2bee8f137222 Mon Sep 17 00:00:00 2001 From: David Lord Date: Fri, 1 Oct 2021 09:46:38 -0700 Subject: [PATCH 3/3] update requirements --- .pre-commit-config.yaml | 4 ++-- requirements/dev.txt | 26 +++++++++++++------------- requirements/docs.txt | 6 +++--- requirements/tests.txt | 2 +- requirements/typing.txt | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b648e3f0..3ef408f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: autoupdate_schedule: monthly repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.25.0 + rev: v2.29.0 hooks: - id: pyupgrade args: ["--py36-plus"] @@ -14,7 +14,7 @@ repos: files: "^(?!examples/)" args: ["--application-directories", "src"] - repo: https://github.com/psf/black - rev: 21.8b0 + rev: 21.9b0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 diff --git a/requirements/dev.txt b/requirements/dev.txt index 4962c2ac..19f50095 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -22,25 +22,25 @@ cffi==1.14.6 # via cryptography cfgv==3.3.1 # via pre-commit -charset-normalizer==2.0.4 +charset-normalizer==2.0.6 # via requests click==8.0.1 # via pip-tools -cryptography==3.4.8 +cryptography==35.0.0 # via -r requirements/typing.in -distlib==0.3.2 +distlib==0.3.3 # via virtualenv docutils==0.16 # via # sphinx # sphinx-tabs -filelock==3.0.12 +filelock==3.2.0 # via # tox # virtualenv -greenlet==1.1.1 +greenlet==1.1.2 # via -r requirements/tests.in -identify==2.2.13 +identify==2.2.15 # via pre-commit idna==3.2 # via requests @@ -68,9 +68,9 @@ pallets-sphinx-themes==2.0.1 # via -r requirements/docs.in pep517==0.11.0 # via pip-tools -pip-tools==6.2.0 +pip-tools==6.3.0 # via -r requirements/dev.in -platformdirs==2.3.0 +platformdirs==2.4.0 # via virtualenv pluggy==1.0.0 # via @@ -106,7 +106,7 @@ six==1.16.0 # virtualenv snowballstemmer==2.1.0 # via sphinx -sphinx==4.1.2 +sphinx==4.2.0 # via # -r requirements/docs.in # pallets-sphinx-themes @@ -139,19 +139,19 @@ toml==0.10.2 # tox tomli==1.2.1 # via pep517 -tox==3.24.3 +tox==3.24.4 # via -r requirements/dev.in types-contextvars==0.1.4 # via -r requirements/typing.in types-dataclasses==0.1.7 # via -r requirements/typing.in -types-setuptools==57.0.2 +types-setuptools==57.4.0 # via -r requirements/typing.in typing-extensions==3.10.0.2 # via mypy -urllib3==1.26.6 +urllib3==1.26.7 # via requests -virtualenv==20.7.2 +virtualenv==20.8.1 # via # pre-commit # tox diff --git a/requirements/docs.txt b/requirements/docs.txt index a11b7d3c..43b83f93 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -10,7 +10,7 @@ babel==2.9.1 # via sphinx certifi==2021.5.30 # via requests -charset-normalizer==2.0.4 +charset-normalizer==2.0.6 # via requests docutils==0.16 # via @@ -42,7 +42,7 @@ requests==2.26.0 # via sphinx snowballstemmer==2.1.0 # via sphinx -sphinx==4.1.2 +sphinx==4.2.0 # via # -r requirements/docs.in # pallets-sphinx-themes @@ -67,7 +67,7 @@ sphinxcontrib-qthelp==1.0.3 # via sphinx sphinxcontrib-serializinghtml==1.1.5 # via sphinx -urllib3==1.26.6 +urllib3==1.26.7 # via requests # The following packages are considered to be unsafe in a requirements file: diff --git a/requirements/tests.txt b/requirements/tests.txt index 66bc443d..11889378 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -10,7 +10,7 @@ attrs==21.2.0 # via pytest blinker==1.4 # via -r requirements/tests.in -greenlet==1.1.1 +greenlet==1.1.2 # via -r requirements/tests.in iniconfig==1.1.1 # via pytest diff --git a/requirements/typing.txt b/requirements/typing.txt index 106a0a21..724aa2a2 100644 --- a/requirements/typing.txt +++ b/requirements/typing.txt @@ -6,7 +6,7 @@ # cffi==1.14.6 # via cryptography -cryptography==3.4.8 +cryptography==35.0.0 # via -r requirements/typing.in mypy==0.910 # via -r requirements/typing.in @@ -20,7 +20,7 @@ types-contextvars==0.1.4 # via -r requirements/typing.in types-dataclasses==0.1.7 # via -r requirements/typing.in -types-setuptools==57.0.2 +types-setuptools==57.4.0 # via -r requirements/typing.in typing-extensions==3.10.0.2 # via mypy