Don't set the cli attribute in the sansio scaffold
Before adoption: this commit came in with the history the project adopted, so no landing records it.
It is (currently) Flask specific and hence cannot be shared in the sansio shared code.
authored by pgjones · committed by David Lord · parent adb7dd9 · Browse files · 5 files·+54 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+54 added−12 removed
- other:+54 added−12 removed
Provenance
- Commit
5fdce4c- Tree
da0daa7- Author
pgjones <philip.graham.jones@googlemail.com>- Committer
David Lord <davidism@gmail.com>- Parent
adb7dd9
5 files changed+54 added−12 removed
modified:src/flask/sansio/app.py-4 removed
408 unmodified lines409 # tracks internally if the application already handled at least one410 # request.411 self._got_first_request = False412 413- # Set the name of the Click group in case someone wants to add414- # the app's commands to another CLI tool.415- self.cli.name = self.name416-413 def _check_setup_finished(self, f_name: str) -> None:414 if self._got_first_request:415 raise AssertionError(416 f"The setup method '{f_name}' can no longer be called"548 unmodified linesmodified:src/flask/sansio/scaffold.py+4 added-8 removed
6 unmodified lines7 import typing as t8 from collections import defaultdict9 from functools import update_wrapper10 11-import click11 from jinja2 import BaseLoader12 from jinja2 import FileSystemLoader13 from werkzeug.exceptions import default_exceptions14 from werkzeug.exceptions import HTTPException15 from werkzeug.utils import cached_property16 17 from .. import typing as ft19-from ..cli import AppGroup18 from ..helpers import get_root_path19 from ..templating import _default_template_ctx_processor20 21+if t.TYPE_CHECKING: # pragma: no cover22+ from click import Group23+24 # a singleton sentinel value for parameter defaults25 _sentinel = object()26 27 F = t.TypeVar("F", bound=t.Callable[..., t.Any])38 unmodified lines66 67 .. versionadded:: 2.068 """69 70+ cli: Group71 name: str72 _static_folder: str | None = None73 _static_url_path: str | None = None74 23 unmodified lines98 #: Absolute path to the package on the filesystem. Used to look99 #: up resources contained in the package.100 self.root_path = root_path101 100- #: The Click command group for registering CLI commands for this101- #: object. The commands are available from the ``flask`` command102- #: once the application has been discovered and blueprints have103- #: been registered.104- self.cli: click.Group = AppGroup()105-102 #: A dictionary mapping endpoint names to view functions.103 #:104 #: To register a view function, use the :meth:`route` decorator.105 #:696 unmodified linesmodified:src/flask/app.py+10 added
239 unmodified lines240 instance_relative_config=instance_relative_config,241 root_path=root_path,242 )243 244+ #: The Click command group for registering CLI commands for this245+ #: object. The commands are available from the ``flask`` command246+ #: once the application has been discovered and blueprints have247+ #: been registered.248+ self.cli = cli.AppGroup()249+250+ # Set the name of the Click group in case someone wants to add251+ # the app's commands to another CLI tool.252+ self.cli.name = self.name253+254 # Add a static route using the provided static_url_path, static_host,255 # and static_folder if there is a configured static_folder.256 # Note we do this without checking if static_folder exists.257 # For one, it might be created while the server is running (e.g. during1241 unmodified linesmodified:src/flask/blueprints.py+38 added
2 unmodified lines3 import os4 import typing as t5 from datetime import timedelta6 7+from .cli import AppGroup8 from .globals import current_app9 from .helpers import send_from_directory10 from .sansio.blueprints import Blueprint as SansioBlueprint11 from .sansio.blueprints import BlueprintSetupState as BlueprintSetupState # noqa12+from .sansio.scaffold import _sentinel13 14 if t.TYPE_CHECKING: # pragma: no cover15 from .wrappers import Response16 17 18 class Blueprint(SansioBlueprint):19+ def __init__(20+ self,21+ name: str,22+ import_name: str,23+ static_folder: str | os.PathLike[str] | None = None,24+ static_url_path: str | None = None,25+ template_folder: str | os.PathLike[str] | None = None,26+ url_prefix: str | None = None,27+ subdomain: str | None = None,28+ url_defaults: dict[str, t.Any] | None = None,29+ root_path: str | None = None,30+ cli_group: str | None = _sentinel, # type: ignore31+ ) -> None:32+ super().__init__(33+ name,34+ import_name,35+ static_folder,36+ static_url_path,37+ template_folder,38+ url_prefix,39+ subdomain,40+ url_defaults,41+ root_path,42+ cli_group,43+ )44+45+ #: The Click command group for registering CLI commands for this46+ #: object. The commands are available from the ``flask`` command47+ #: once the application has been discovered and blueprints have48+ #: been registered.49+ self.cli = AppGroup()50+51+ # Set the name of the Click group in case someone wants to add52+ # the app's commands to another CLI tool.53+ self.cli.name = self.name54+55 def get_send_file_max_age(self, filename: str | None) -> int | None:56 """Used by :func:`send_file` to determine the ``max_age`` cache57 value for a given file path if it wasn't passed.58 71 unmodified linesmodified:CHANGES.rst+2 added
4 unmodified lines5 6 - The default ``hashlib.sha1`` may not be available in FIPS builds. Don't7 access it at import time so the developer has time to change the default.8 :issue:`5448`9+- Don't initialize the ``cli`` attribute in the sansio scaffold, but rather in10+ the ``Flask`` concrete class. :pr:`5270`11 12 13 Version 3.0.214 -------------1551 unmodified lines