From c3d04ab19306c93c9d6af60d185214799700478a Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 22 May 2024 17:58:32 +0200 Subject: [PATCH] euicc.py: Resolve possible variable use before assignment pySim/euicc.py:436:31: E0606: Possibly using variable 'p_id' before assignment (possibly-used-before-assignment) pySim/euicc.py:455:31: E0606: Possibly using variable 'p_id' before assignment (possibly-used-before-assignment) pySim/euicc.py:473:31: E0606: Possibly using variable 'p_id' before assignment (possibly-used-before-assignment) Let's raise an exception in the erroneous case. Change-Id: Ifdf4651e503bae6ea3e91c89c2121b416a12fb1a --- pySim/euicc.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pySim/euicc.py b/pySim/euicc.py index c27c91f6..7f4cddad 100644 --- a/pySim/euicc.py +++ b/pySim/euicc.py @@ -429,8 +429,11 @@ class CardApplicationISDR(pySim.global_platform.CardApplicationSD): """Perform an ES10c EnableProfile function.""" if opts.isdp_aid: p_id = ProfileIdentifier(children=[IsdpAid(decoded=opts.isdp_aid)]) - if opts.iccid: + elif opts.iccid: p_id = ProfileIdentifier(children=[Iccid(decoded=opts.iccid)]) + else: + # this is guaranteed by argparse; but we need this to make pylint happy + raise ValueError('Either ISD-P AID or ICCID must be given') ep_cmd_contents = [p_id, RefreshFlag(decoded=opts.refresh_required)] ep_cmd = EnableProfileReq(children=ep_cmd_contents) ep = CardApplicationISDR.store_data_tlv(self._cmd.lchan.scc, ep_cmd, EnableProfileResp) @@ -448,8 +451,11 @@ class CardApplicationISDR(pySim.global_platform.CardApplicationSD): """Perform an ES10c DisableProfile function.""" if opts.isdp_aid: p_id = ProfileIdentifier(children=[IsdpAid(decoded=opts.isdp_aid)]) - if opts.iccid: + elif opts.iccid: p_id = ProfileIdentifier(children=[Iccid(decoded=opts.iccid)]) + else: + # this is guaranteed by argparse; but we need this to make pylint happy + raise ValueError('Either ISD-P AID or ICCID must be given') dp_cmd_contents = [p_id, RefreshFlag(decoded=opts.refresh_required)] dp_cmd = DisableProfileReq(children=dp_cmd_contents) dp = CardApplicationISDR.store_data_tlv(self._cmd.lchan.scc, dp_cmd, DisableProfileResp) @@ -466,8 +472,11 @@ class CardApplicationISDR(pySim.global_platform.CardApplicationSD): """Perform an ES10c DeleteProfile function.""" if opts.isdp_aid: p_id = IsdpAid(decoded=opts.isdp_aid) - if opts.iccid: + elif opts.iccid: p_id = Iccid(decoded=opts.iccid) + else: + # this is guaranteed by argparse; but we need this to make pylint happy + raise ValueError('Either ISD-P AID or ICCID must be given') dp_cmd_contents = [p_id] dp_cmd = DeleteProfileReq(children=dp_cmd_contents) dp = CardApplicationISDR.store_data_tlv(self._cmd.lchan.scc, dp_cmd, DeleteProfileResp)