33"""
44
55import logging
6+ import os .path
7+ import sys
8+ from typing import Any
69
710import arrow
811import click
912
1013from git_pw import api
1114from git_pw import utils
12- import os .path
13- import sys
1415
1516LOG = logging .getLogger (__name__ )
1617
@@ -44,7 +45,7 @@ def apply_cmd(series_id, args, deps):
4445 series = api .detail ('series' , series_id )
4546
4647 # .mbox files are applied in the order they appear in this list.
47- to_apply = []
48+ to_apply : list [ Any ] = []
4849
4950 if deps :
5051 if dependencies := series .get ('dependencies' ):
@@ -66,7 +67,8 @@ def apply_cmd(series_id, args, deps):
6667
6768 for mbox_url in to_apply :
6869 mbox = api .download (mbox_url )
69- utils .git_am (mbox , args )
70+ if mbox :
71+ utils .git_am (mbox , args )
7072
7173
7274@click .command (name = 'download' )
@@ -109,7 +111,7 @@ def download_cmd(series_id, output, fmt):
109111 )
110112 sys .exit (1 )
111113
112- for patch in series .get ('patches' ):
114+ for patch in series .get ('patches' ) or [] :
113115 path = api .download (patch ['mbox' ], output = output )
114116 if path :
115117 LOG .info (
@@ -149,15 +151,15 @@ def _format_submission(submission):
149151 (
150152 'Submitter' ,
151153 '{} ({})' .format (
152- series .get ('submitter' ).get ('name' ),
153- series .get ('submitter' ).get ('email' ),
154+ ( series .get ('submitter' ) or {} ).get ('name' ),
155+ ( series .get ('submitter' ) or {} ).get ('email' ),
154156 ),
155157 ),
156- ('Project' , series .get ('project' ).get ('name' )),
158+ ('Project' , ( series .get ('project' ) or {} ).get ('name' )),
157159 ('Version' , series .get ('version' )),
158160 (
159161 'Received' ,
160- '%d of %d' % (series . get ( 'received_total' ) , series . get ( 'total' ) ),
162+ '%d of %d' % (series [ 'received_total' ] , series [ 'total' ] ),
161163 ),
162164 ('Complete' , series .get ('received_all' )),
163165 (
@@ -171,7 +173,7 @@ def _format_submission(submission):
171173 ]
172174
173175 prefix = 'Patches'
174- for patch in series .get ('patches' ):
176+ for patch in series .get ('patches' ) or [] :
175177 output .append ((prefix , _format_submission (patch )))
176178 prefix = ''
177179
@@ -239,17 +241,17 @@ def list_cmd(submitters, limit, page, sort, fmt, headers, name, since, before):
239241
240242 # Format and print output
241243
242- output = []
244+ output : list [ Any ] = []
243245
244246 for series_ in series :
245247 item = [
246248 series_ .get ('id' ),
247- arrow .get (series_ . get ( 'date' ) ).humanize (),
249+ arrow .get (series_ [ 'date' ] ).humanize (),
248250 utils .trim (series_ .get ('name' ) or '' ),
249251 series_ .get ('version' ),
250252 '{} ({})' .format (
251- series_ .get ('submitter' ).get ('name' ),
252- series_ .get ('submitter' ).get ('email' ),
253+ ( series_ .get ('submitter' ) or {} ).get ('name' ),
254+ ( series_ .get ('submitter' ) or {} ).get ('email' ),
253255 ),
254256 ]
255257
0 commit comments