Reconcile #2811 and #2840
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kevin Deldycke · committed by Kevin Deldycke · parent 07207ad · Browse files · 1 file·+26 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+26 added−8 removed
- other:+26 added−8 removed
Provenance
- Commit
46c32a1- Tree
4d4fafa- Author
Kevin Deldycke <kevin@deldycke.com>- Committer
Kevin Deldycke <kevin@deldycke.com>- Parent
07207ad
1 file changed+26 added−8 removed
modified:src/click/core.py+26 added-8 removed
114 unmodified lines115 def iter_params_for_processing(116 invocation_order: cabc.Sequence[Parameter],117 declaration_order: cabc.Sequence[Parameter],118 ) -> list[Parameter]:119- """Given a sequence of parameters in the order as should be considered120- for processing and an iterable of parameters that exist, this returns121- a list in the correct order as they should be processed.119+ """Returns all declared parameters in the order they should be processed.120+121+ The declared parameters are re-shuffled depending on the order in which122+ they were invoked, as well as the eagerness of each parameters.123+124+ The invocation order takes precedence over the declaration order. I.e. the125+ order in which the user provided them to the CLI is respected.126+127+ This behavior and its effect on callback evaluation is detailed at:128+ https://click.palletsprojects.com/en/stable/advanced/#callback-evaluation-order129 """130 131 def sort_key(item: Parameter) -> tuple[bool, float]:132 try:807 unmodified lines940 self.epilog = epilog941 self.options_metavar = options_metavar942 self.short_help = short_help943 self.add_help_option = add_help_option944+ self._help_option = None945 self.no_args_is_help = no_args_is_help946 self.hidden = hidden947 self.deprecated = deprecated948 75 unmodified lines1024 def get_help_option(self, ctx: Context) -> Option | None:1025 """Returns the help option object.1026 1027 Skipped if :attr:`add_help_option` is ``False``.1028+1029+ .. versionchanged:: 8.1.81030+ The help option is now cached to avoid creating it multiple times.1031 """1032 help_option_names = self.get_help_option_names(ctx)1033 1034 if not help_option_names or not self.add_help_option:1035 return None1036 1037+ # Cache the help option object in private _help_option attribute to1038+ # avoid creating it multiple times. Not doing this will break the1039+ # callback odering by iter_params_for_processing(), which relies on1040+ # object comparison.1041+ if self._help_option is None:1026- # Avoid circular import.1027- from .decorators import help_option1042+ # Avoid circular import.1043+ from .decorators import help_option1044 1029- # apply help_option decorator and pop resulting option1030- help_option(*help_option_names)(self)1031- return self.params.pop() # type: ignore[return-value]1045+ # Apply help_option decorator and pop resulting option1046+ help_option(*help_option_names)(self)1047+ self._help_option = self.params.pop() # type: ignore[assignment]1048 1049+ return self._help_option1050+1051 def make_parser(self, ctx: Context) -> _OptionParser:1052 """Creates the underlying option parser for this command."""1053 parser = _OptionParser(ctx)1054 for param in self.get_params(ctx):2081 unmodified lines