From 233f2abf191c333803e3c9d0b37c6c276f417e23 Mon Sep 17 00:00:00 2001 From: Chandan Singh Date: Mon, 3 Jun 2019 16:13:52 +0100 Subject: [PATCH] click: Use property decorator for read-only properties (#3028) Since these properties do not have a setter, be explicit with the `@property` decorator. This will allow type checkers to see that assignment of these attributes is an error. See https://github.com/python/typeshed/pull/3027#discussion_r289623016 for some related context. --- third_party/2and3/click/core.pyi | 18 ++++++++++++------ third_party/2and3/click/parser.pyi | 6 ++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/third_party/2and3/click/core.pyi b/third_party/2and3/click/core.pyi index 302e2a52f..fa2413d69 100644 --- a/third_party/2and3/click/core.pyi +++ b/third_party/2and3/click/core.pyi @@ -65,10 +65,6 @@ class Context: _close_callbacks: List _depth: int - # properties - meta: Dict[str, Any] - command_path: str - def __init__( self, command: Command, @@ -89,6 +85,14 @@ class Context: ) -> None: ... + @property + def meta(self) -> Dict[str, Any]: + ... + + @property + def command_path(self) -> str: + ... + def scope(self, cleanup: bool = ...) -> ContextManager[Context]: ... @@ -370,8 +374,6 @@ class Parameter: is_eager: bool metavar: Optional[str] envvar: Union[str, List[str], None] - # properties - human_readable_name: str def __init__( self, @@ -388,6 +390,10 @@ class Parameter: ) -> None: ... + @property + def human_readable_name(self) -> str: + ... + def make_metavar(self) -> str: ... diff --git a/third_party/2and3/click/parser.pyi b/third_party/2and3/click/parser.pyi index f5869a27d..d790bacbc 100644 --- a/third_party/2and3/click/parser.pyi +++ b/third_party/2and3/click/parser.pyi @@ -30,8 +30,6 @@ class Option: prefixes: Set[str] _short_opts: List[str] _long_opts: List[str] - # properties - takes_value: bool def __init__( self, @@ -44,6 +42,10 @@ class Option: ) -> None: ... + @property + def takes_value(self) -> bool: + ... + def process(self, value: Any, state: ParsingState) -> None: ...