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
Provenance
- Commit
8473b3c- Tree
3a59aac- Author
Kyle Altendorf <sda@fstab.net>- Committer
GitHub <noreply@github.com>- Parent
e002dbc
3 files changed+18 added−11 removed
modified:src/click/core.py+10 added-8 removed
262 unmodified lines263 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 lines310 and parent.default_map is not None311 ):312 default_map = parent.default_map.get(info_name)313 314- self.default_map: t.Optional[t.Dict[str, t.Any]] = default_map314+ self.default_map: t.Optional[t.MutableMapping[str, t.Any]] = default_map315 316 #: 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 passes542 unmodified lines861 862 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 the3 unmodified lines873 if context_settings is None:874 context_settings = {}875 876 #: 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_settings878 879 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 structure234 unmodified lines1116 sys.exit(1)1117 1118 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, process67 unmodified lines1192 1193 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 lines1803 1804 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 lines1816 elif isinstance(commands, abc.Sequence):1817 commands = {c.name: c for c in commands if c.name is not None}1818 1819 #: The registered subcommands by their exported names.1818- self.commands: t.Dict[str, Command] = commands1820+ self.commands: t.MutableMapping[str, Command] = commands1821 1822 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 linesmodified:src/click/shell_completion.py+6 added-3 removed
14 unmodified lines15 16 17 def 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 lines213 214 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 = cli264 unmodified lines486 return last_option is not None and last_option in param.opts487 488 489 def _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 linesmodified:CHANGES.rst+2 added
3 unmodified lines4 -------------5 6 Unreleased7 8+- 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