Skip to content

Commit 156114e

Browse files
typing: add typing to dogshell (#919)
1 parent 80a5445 commit 156114e

20 files changed

+183
-15
lines changed

datadog/dogshell/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232

3333
def main():
34+
# type: () -> None
3435
if sys.argv[0].endswith("dog"):
3536
warnings.warn("dog is pending deprecation. Please use dogshell instead.", PendingDeprecationWarning)
3637

datadog/dogshell/comment.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# This product includes software developed at Datadog (https://www.datadoghq.com/).
33
# Copyright 2015-Present Datadog, Inc
44
# stdlib
5+
import argparse
56
import json
67
import sys
78

@@ -13,6 +14,7 @@
1314
class CommentClient(object):
1415
@classmethod
1516
def setup_parser(cls, subparsers):
17+
# type: (argparse._SubParsersAction[argparse.ArgumentParser]) -> None
1618
parser = subparsers.add_parser("comment", help="Post, update, and delete comments.")
1719

1820
verb_parsers = parser.add_subparsers(title="Verbs", dest="verb")
@@ -41,6 +43,7 @@ def setup_parser(cls, subparsers):
4143

4244
@classmethod
4345
def _post(cls, args):
46+
# type: (argparse.Namespace) -> None
4447
api._timeout = args.timeout
4548
handle = args.handle
4649
comment = args.comment
@@ -70,6 +73,7 @@ def _post(cls, args):
7073

7174
@classmethod
7275
def _update(cls, args):
76+
# type: (argparse.Namespace) -> None
7377
handle = args.handle
7478
comment = args.comment
7579
id = args.comment_id
@@ -99,6 +103,7 @@ def _update(cls, args):
99103

100104
@classmethod
101105
def _reply(cls, args):
106+
# type: (argparse.Namespace) -> None
102107
api._timeout = args.timeout
103108
handle = args.handle
104109
comment = args.comment
@@ -129,6 +134,7 @@ def _reply(cls, args):
129134

130135
@classmethod
131136
def _show(cls, args):
137+
# type: (argparse.Namespace) -> None
132138
api._timeout = args.timeout
133139
id = args.comment_id
134140
format = args.format

datadog/dogshell/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
from __future__ import print_function
66
import os
77
import sys
8+
from typing import Any, Dict, Optional
89

910
# datadog
1011
from datadog.util.compat import is_p3k, configparser, IterableUserDict, get_input
1112

1213

1314
def print_err(msg):
15+
# type: (str) -> None
1416
if is_p3k():
1517
print(msg + "\n", file=sys.stderr)
1618
else:
@@ -19,6 +21,7 @@ def print_err(msg):
1921

2022

2123
def report_errors(res):
24+
# type: (Dict[str, Any]) -> bool
2225
if "errors" in res:
2326
errors = res["errors"]
2427
if isinstance(errors, list):
@@ -31,6 +34,7 @@ def report_errors(res):
3134

3235

3336
def report_warnings(res):
37+
# type: (Dict[str, Any]) -> bool
3438
if "warnings" in res:
3539
warnings = res["warnings"]
3640
if isinstance(warnings, list):
@@ -44,6 +48,7 @@ def report_warnings(res):
4448

4549
class DogshellConfig(IterableUserDict):
4650
def load(self, config_file, api_key, app_key, api_host):
51+
# type: (str, Optional[str], Optional[str], Optional[str]) -> None
4752
config = configparser.ConfigParser()
4853

4954
if api_host is not None:

datadog/dogshell/dashboard.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# 3p
99
import argparse
10+
from typing import Any
1011

1112
# datadog
1213
from datadog import api
@@ -17,6 +18,7 @@
1718
class DashboardClient(object):
1819
@classmethod
1920
def setup_parser(cls, subparsers):
21+
# type: (argparse._SubParsersAction[argparse.ArgumentParser]) -> None
2022
parser = subparsers.add_parser("dashboard", help="Create, edit, and delete dashboards")
2123

2224
verb_parsers = parser.add_subparsers(title="Verbs", dest="verb")
@@ -89,6 +91,7 @@ def setup_parser(cls, subparsers):
8991

9092
@classmethod
9193
def _post(cls, args):
94+
# type: (argparse.Namespace) -> None
9295
api._timeout = args.timeout
9396
format = args.format
9497
widgets = args.widgets
@@ -118,6 +121,7 @@ def _post(cls, args):
118121

119122
@classmethod
120123
def _update(cls, args):
124+
# type: (argparse.Namespace) -> None
121125
api._timeout = args.timeout
122126
format = args.format
123127
widgets = args.widgets
@@ -147,6 +151,7 @@ def _update(cls, args):
147151

148152
@classmethod
149153
def _show(cls, args):
154+
# type: (argparse.Namespace) -> None
150155
api._timeout = args.timeout
151156
format = args.format
152157
res = api.Dashboard.get(args.dashboard_id)
@@ -160,6 +165,7 @@ def _show(cls, args):
160165

161166
@classmethod
162167
def _delete(cls, args):
168+
# type: (argparse.Namespace) -> None
163169
api._timeout = args.timeout
164170
res = api.Dashboard.delete(args.dashboard_id)
165171
if res is not None:
@@ -168,6 +174,7 @@ def _delete(cls, args):
168174

169175

170176
def _json_string(str):
177+
# type: (str) -> Any
171178
try:
172179
return json.loads(str)
173180
except Exception:

datadog/dogshell/dashboard_list.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# This product includes software developed at Datadog (https://www.datadoghq.com/).
33
# Copyright 2015-Present Datadog, Inc
44
# stdlib
5+
import argparse
56
import json
67

78
# 3p
@@ -15,6 +16,7 @@
1516
class DashboardListClient(object):
1617
@classmethod
1718
def setup_parser(cls, subparsers):
19+
# type: (argparse._SubParsersAction[argparse.ArgumentParser]) -> None
1820
parser = subparsers.add_parser("dashboard_list", help="Create, edit, and delete dashboard lists")
1921
verb_parsers = parser.add_subparsers(title="Verbs", dest="verb")
2022
verb_parsers.required = True
@@ -139,6 +141,7 @@ def setup_parser(cls, subparsers):
139141

140142
@classmethod
141143
def _post(cls, args):
144+
# type: (argparse.Namespace) -> None
142145
api._timeout = args.timeout
143146
format = args.format
144147
name = args.name
@@ -154,6 +157,7 @@ def _post(cls, args):
154157

155158
@classmethod
156159
def _update(cls, args):
160+
# type: (argparse.Namespace) -> None
157161
api._timeout = args.timeout
158162
format = args.format
159163
dashboard_list_id = args.dashboard_list_id
@@ -170,6 +174,7 @@ def _update(cls, args):
170174

171175
@classmethod
172176
def _show(cls, args):
177+
# type: (argparse.Namespace) -> None
173178
api._timeout = args.timeout
174179
format = args.format
175180
dashboard_list_id = args.dashboard_list_id
@@ -185,6 +190,7 @@ def _show(cls, args):
185190

186191
@classmethod
187192
def _show_all(cls, args):
193+
# type: (argparse.Namespace) -> None
188194
api._timeout = args.timeout
189195
format = args.format
190196

@@ -199,6 +205,7 @@ def _show_all(cls, args):
199205

200206
@classmethod
201207
def _delete(cls, args):
208+
# type: (argparse.Namespace) -> None
202209
api._timeout = args.timeout
203210
format = args.format
204211
dashboard_list_id = args.dashboard_list_id
@@ -214,6 +221,7 @@ def _delete(cls, args):
214221

215222
@classmethod
216223
def _show_dashboards(cls, args):
224+
# type: (argparse.Namespace) -> None
217225
api._timeout = args.timeout
218226
format = args.format
219227
dashboard_list_id = args.dashboard_list_id
@@ -229,6 +237,7 @@ def _show_dashboards(cls, args):
229237

230238
@classmethod
231239
def _show_dashboards_v2(cls, args):
240+
# type: (argparse.Namespace) -> None
232241
api._timeout = args.timeout
233242
format = args.format
234243
dashboard_list_id = args.dashboard_list_id
@@ -244,6 +253,7 @@ def _show_dashboards_v2(cls, args):
244253

245254
@classmethod
246255
def _add_dashboards(cls, args):
256+
# type: (argparse.Namespace) -> None
247257
api._timeout = args.timeout
248258
format = args.format
249259
dashboard_list_id = args.dashboard_list_id
@@ -260,6 +270,7 @@ def _add_dashboards(cls, args):
260270

261271
@classmethod
262272
def _add_dashboards_v2(cls, args):
273+
# type: (argparse.Namespace) -> None
263274
api._timeout = args.timeout
264275
format = args.format
265276
dashboard_list_id = args.dashboard_list_id
@@ -276,6 +287,7 @@ def _add_dashboards_v2(cls, args):
276287

277288
@classmethod
278289
def _update_dashboards(cls, args):
290+
# type: (argparse.Namespace) -> None
279291
api._timeout = args.timeout
280292
format = args.format
281293
dashboard_list_id = args.dashboard_list_id
@@ -292,6 +304,7 @@ def _update_dashboards(cls, args):
292304

293305
@classmethod
294306
def _update_dashboards_v2(cls, args):
307+
# type: (argparse.Namespace) -> None
295308
api._timeout = args.timeout
296309
format = args.format
297310
dashboard_list_id = args.dashboard_list_id
@@ -308,6 +321,7 @@ def _update_dashboards_v2(cls, args):
308321

309322
@classmethod
310323
def _delete_dashboards(cls, args):
324+
# type: (argparse.Namespace) -> None
311325
api._timeout = args.timeout
312326
format = args.format
313327
dashboard_list_id = args.dashboard_list_id
@@ -324,6 +338,7 @@ def _delete_dashboards(cls, args):
324338

325339
@classmethod
326340
def _delete_dashboards_v2(cls, args):
341+
# type: (argparse.Namespace) -> None
327342
api._timeout = args.timeout
328343
format = args.format
329344
dashboard_list_id = args.dashboard_list_id

datadog/dogshell/downtime.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# This product includes software developed at Datadog (https://www.datadoghq.com/).
33
# Copyright 2015-Present Datadog, Inc
44
# stdlib
5+
import argparse
56
import json
67

78
# 3p
@@ -15,6 +16,7 @@
1516
class DowntimeClient(object):
1617
@classmethod
1718
def setup_parser(cls, subparsers):
19+
# type: (argparse._SubParsersAction[argparse.ArgumentParser]) -> None
1820
parser = subparsers.add_parser("downtime", help="Create, edit, and delete downtimes")
1921
parser.add_argument(
2022
"--string_ids",
@@ -65,6 +67,7 @@ def setup_parser(cls, subparsers):
6567

6668
@classmethod
6769
def _schedule_downtime(cls, args):
70+
# type: (argparse.Namespace) -> None
6871
api._timeout = args.timeout
6972
format = args.format
7073
res = api.Downtime.create(scope=args.scope, start=args.start, end=args.end, message=args.message)
@@ -77,6 +80,7 @@ def _schedule_downtime(cls, args):
7780

7881
@classmethod
7982
def _update_downtime(cls, args):
83+
# type: (argparse.Namespace) -> None
8084
api._timeout = args.timeout
8185
format = args.format
8286
res = api.Downtime.update(
@@ -91,6 +95,7 @@ def _update_downtime(cls, args):
9195

9296
@classmethod
9397
def _cancel_downtime(cls, args):
98+
# type: (argparse.Namespace) -> None
9499
api._timeout = args.timeout
95100
res = api.Downtime.delete(args.downtime_id)
96101
if res is not None:
@@ -99,6 +104,7 @@ def _cancel_downtime(cls, args):
99104

100105
@classmethod
101106
def _show_downtime(cls, args):
107+
# type: (argparse.Namespace) -> None
102108
api._timeout = args.timeout
103109
format = args.format
104110
res = api.Downtime.get(args.downtime_id)
@@ -111,6 +117,7 @@ def _show_downtime(cls, args):
111117

112118
@classmethod
113119
def _show_all_downtime(cls, args):
120+
# type: (argparse.Namespace) -> None
114121
api._timeout = args.timeout
115122
format = args.format
116123
res = api.Downtime.get_all(current_only=args.current_only)
@@ -123,6 +130,7 @@ def _show_all_downtime(cls, args):
123130

124131
@classmethod
125132
def _cancel_downtime_by_scope(cls, args):
133+
# type: (argparse.Namespace) -> None
126134
api._timeout = args.timeout
127135
format = args.format
128136
res = api.Downtime.cancel_downtime_by_scope(scope=args.scope)

0 commit comments

Comments
 (0)