Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork960
Commit5d7e55b
committed
Add return-type annotation on __init__ methods
Although sometimes found unintuitive, the reutrn type of a class's__init__ method is best annotated as None, as in other functionsthat return implicitly or by operand-less return statements.Note that this is only a minor improvement, effectively just astyle fix, because mypy treats __init__ specially and, *when atleast one parameter is annotated*, its return type is implicitlyNone rather than implicitly Any like other functions. All the__init__ methods modified here did already have one or moreannotated parameters.However, having __init__ methods without the return type makes iteasier to introduce a bug where an __init__ method with noparameters besides self -- which itself should almost always beunannotated and is properly inferred -- is written and the returnannotation needed to get mypy to regard it as statically typed,so it checks it at all, is omitted. (It is also inelegant whenone considers the meaning of __init__ and the distinction betweenit and __new__.)This commit does not add any return type annotations to functionsin the test suite, since the test suite doesn't currently usestatic typing.Further reading:-https://peps.python.org/pep-0484/#the-meaning-of-annotations-python/mypy#604-#1755 (comment)1 parente984bfe commit5d7e55b
7 files changed
+7
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
846 | 846 | | |
847 | 847 | | |
848 | 848 | | |
849 | | - | |
| 849 | + | |
850 | 850 | | |
851 | 851 | | |
852 | 852 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
917 | 917 | | |
918 | 918 | | |
919 | 919 | | |
920 | | - | |
| 920 | + | |
921 | 921 | | |
922 | 922 | | |
923 | 923 | | |
| |||
0 commit comments
Comments
(0)