Skip to content
Myr

Use t.Mapping not t.Dict for parameters (#2265)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kyle Altendorf · committed by GitHub · parent e002dbc · Browse files · 3 files+18 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Co-authored-by: Sagi Buchbinder Shadur <saroad2@gmail.com>

Diff stats

3 files+18 added−11 removed

  • other:+18 added−11 removed

3 files+18 added−11 removed

modified:src/click/core.py+10 added-8 removed
262 unmodified lines
263 parent: t.Optional["Context"] = None,264 info_name: t.Optional[str] = None,265 obj: t.Optional[t.Any] = None,266 auto_envvar_prefix: t.Optional[str] = None,267 default_map: t.Optional[t.Dict[str, t.Any]] = None,267 default_map: t.Optional[t.MutableMapping[str, t.Any]] = None,268 terminal_width: t.Optional[int] = None,269 max_content_width: t.Optional[int] = None,270 resilient_parsing: bool = False,271 allow_extra_args: t.Optional[bool] = None,
38 unmodified lines
310 and parent.default_map is not None311 ):312 default_map = parent.default_map.get(info_name)313314 self.default_map: t.Optional[t.Dict[str, t.Any]] = default_map314 self.default_map: t.Optional[t.MutableMapping[str, t.Any]] = default_map315316 #: This flag indicates if a subcommand is going to be executed. A317 #: group callback can use this information to figure out if it's318 #: being executed directly or because the execution flow passes
542 unmodified lines
861862 def __init__(863 self,864 name: t.Optional[str],865 context_settings: t.Optional[t.Dict[str, t.Any]] = None,865 context_settings: t.Optional[t.MutableMapping[str, t.Any]] = None,866 ) -> None:867 #: the name the command thinks it has. Upon registering a command868 #: on a :class:`Group` the group will default the command name869 #: with this information. You should instead use the
3 unmodified lines
873 if context_settings is None:874 context_settings = {}875876 #: an optional dictionary with defaults passed to the context.877 self.context_settings: t.Dict[str, t.Any] = context_settings877 self.context_settings: t.MutableMapping[str, t.Any] = context_settings878879 def to_info_dict(self, ctx: Context) -> t.Dict[str, t.Any]:880 """Gather information that could be useful for a tool generating881 user-facing documentation. This traverses the entire structure
234 unmodified lines
1116 sys.exit(1)11171118 def _main_shell_completion(1119 self,1120 ctx_args: t.Dict[str, t.Any],1120 ctx_args: t.MutableMapping[str, t.Any],1121 prog_name: str,1122 complete_var: t.Optional[str] = None,1123 ) -> None:1124 """Check if the shell is asking for tab completion, process
67 unmodified lines
11921193 def __init__(1194 self,1195 name: t.Optional[str],1196 context_settings: t.Optional[t.Dict[str, t.Any]] = None,1196 context_settings: t.Optional[t.MutableMapping[str, t.Any]] = None,1197 callback: t.Optional[t.Callable[..., t.Any]] = None,1198 params: t.Optional[t.List["Parameter"]] = None,1199 help: t.Optional[str] = None,1200 epilog: t.Optional[str] = None,
602 unmodified lines
18031804 def __init__(1805 self,1806 name: t.Optional[str] = None,1807 commands: t.Optional[t.Union[t.Dict[str, Command], t.Sequence[Command]]] = None,1807 commands: t.Optional[1808 t.Union[t.MutableMapping[str, Command], t.Sequence[Command]]1809 ] = None,1810 **attrs: t.Any,1811 ) -> None:1812 super().__init__(name, **attrs)1813
2 unmodified lines
1816 elif isinstance(commands, abc.Sequence):1817 commands = {c.name: c for c in commands if c.name is not None}18181819 #: The registered subcommands by their exported names.1818 self.commands: t.Dict[str, Command] = commands1820 self.commands: t.MutableMapping[str, Command] = commands18211822 def add_command(self, cmd: Command, name: t.Optional[str] = None) -> None:1823 """Registers another :class:`Command` with this group. If the name1824 is not provided, the name of the command is used.
1194 unmodified lines
modified:src/click/shell_completion.py+6 added-3 removed
14 unmodified lines
151617def shell_complete(18 cli: BaseCommand,19 ctx_args: t.Dict[str, t.Any],19 ctx_args: t.MutableMapping[str, t.Any],20 prog_name: str,21 complete_var: str,22 instruction: str,23) -> int:
189 unmodified lines
213214 def __init__(215 self,216 cli: BaseCommand,217 ctx_args: t.Dict[str, t.Any],217 ctx_args: t.MutableMapping[str, t.Any],218 prog_name: str,219 complete_var: str,220 ) -> None:221 self.cli = cli
264 unmodified lines
486 return last_option is not None and last_option in param.opts487488489def _resolve_context(490 cli: BaseCommand, ctx_args: t.Dict[str, t.Any], prog_name: str, args: t.List[str]490 cli: BaseCommand,491 ctx_args: t.MutableMapping[str, t.Any],492 prog_name: str,493 args: t.List[str],494) -> Context:495 """Produce the context hierarchy starting with the command and496 traversing the complete arguments. This only follows the commands,497 it doesn't trigger input prompts or callbacks.
91 unmodified lines
modified:CHANGES.rst+2 added
3 unmodified lines
4-------------56Unreleased78- Replace all ``typing.Dict`` occurrences to ``typing.MutableMapping`` for9 parameter hints. :issue:`2255`10- Improve type hinting for decorators and give all generic types parameters.11 :issue:`2398`12- Fix return value and type signature of `shell_completion.add_completion_class` function. :pr:`2421`13
1043 unmodified lines