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.
This commit is contained in:
Chandan Singh
2019-06-03 16:13:52 +01:00
committed by Jelle Zijlstra
parent 018ecb3f16
commit 233f2abf19
2 changed files with 16 additions and 8 deletions

View File

@@ -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:
...

View File

@@ -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:
...