Skip to content

Commit 38a022f

Browse files
make update to docs about typing model ivars (Azure#28217)
* make update about typing model ivars * add that ivar docstrings and redundant, not that they aren't needed * offline feedback * missing param docstring for kind
1 parent 0a54c44 commit 38a022f

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

doc/dev/static_type_checking_cheat_sheet.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,30 @@ class KeyCredential:
5050
...
5151
```
5252

53-
- Do provide type annotations for all instance variables on a model. You can do this by typing the parameters in the
54-
`__init__` or by adding type hints directly to the instance variables.
53+
- Do provide type annotations for all public instance variables on a model. Do this by adding class-level type hints
54+
per [PEP526](https://peps.python.org/pep-0526/).
5555

5656
```python
5757
class Tree:
58-
59-
def __init__(self, *, location: str, num_branches: int) -> None:
60-
self.kind: typing.Literal["oak"] = "oak"
58+
"""Represents a tree.
59+
60+
:param str location: The location for the tree.
61+
:param int num_branches: The number of branches on the tree
62+
:param str kind: The kind of tree.
63+
64+
Note: :ivar: docstrings are redundant since these vars/types are captured below
65+
"""
66+
67+
location: str
68+
"""A description of the location of the tree."""
69+
num_branches: int
70+
"""Number of branches on tree."""
71+
kind: str = "oak"
72+
"""The kind of tree."""
73+
74+
def __init__(self, *, location: str, num_branches: int, kind: Optional[str] = None) -> None:
75+
if kind:
76+
self.kind = kind
6177
self.location = location
6278
self.num_branches = num_branches
6379
```

0 commit comments

Comments
 (0)