1616"""
1717# isort: STDLIB
1818from abc import ABC , abstractmethod
19+ from argparse import Namespace
1920from enum import Enum
21+ from typing import Callable , Dict , Union
22+ from uuid import UUID
2023
2124
2225class YesOrNo (Enum ):
@@ -27,10 +30,10 @@ class YesOrNo(Enum):
2730 YES = "yes"
2831 NO = "no"
2932
30- def __bool__ (self ):
33+ def __bool__ (self ) -> bool :
3134 return self is YesOrNo .YES
3235
33- def __str__ (self ):
36+ def __str__ (self ) -> str :
3437 return self .value
3538
3639
@@ -42,7 +45,7 @@ class IdType(Enum):
4245 UUID = "UUID"
4346 NAME = "name"
4447
45- def __str__ (self ):
48+ def __str__ (self ) -> str :
4649 return self .value
4750
4851
@@ -51,22 +54,26 @@ class Id(ABC):
5154 Generic management of ids when either a UUID or name can be used.
5255 """
5356
54- def __init__ (self , id_type , id_value ):
57+ def __init__ (self , id_type : IdType , id_value : Union [ UUID , str ] ):
5558 """
5659 Initialize the object.
5760 """
61+ assert (id_type is IdType .UUID ) == isinstance (id_value , UUID )
62+
5863 self .id_type = id_type
5964 self .id_value = id_value
6065
61- def managed_objects_key (self ):
66+ def managed_objects_key (
67+ self ,
68+ ):
6269 """
6370 Return key for managed objects.
6471
6572 Precondition: the D-Bus property that identifies the Name or the
6673 Uuid will always be the same.
6774 """
6875 return (
69- {"Uuid" : self .id_value .hex }
76+ {"Uuid" : self .id_value .hex } # pyright: ignore [ reportAttributeAccessIssue]
7077 if self .id_type is IdType .UUID
7178 else {"Name" : self .id_value }
7279 )
@@ -78,7 +85,10 @@ def dbus_args(self):
7885 return (
7986 {"id" : self .id_value , "id_type" : "name" }
8087 if self .id_type is IdType .NAME
81- else {"id" : self .id_value .hex , "id_type" : "uuid" }
88+ else {
89+ "id" : self .id_value .hex , # pyright: ignore [ reportAttributeAccessIssue]
90+ "id_type" : "uuid" ,
91+ }
8292 )
8393
8494 @abstractmethod
@@ -101,12 +111,12 @@ class PoolId(Id):
101111 Pool id.
102112 """
103113
104- def __str__ (self ):
114+ def __str__ (self ) -> str :
105115 return f"pool with { self .id_type } { self .id_value } "
106116
107117 @staticmethod
108118 def from_parser_namespace ( # pyright: ignore [reportIncompatibleMethodOverride]
109- namespace , * , required = True
119+ namespace : Namespace , * , required = True
110120 ):
111121 assert hasattr (namespace , "name" ) and hasattr (namespace , "uuid" )
112122 if namespace .uuid is not None :
@@ -118,12 +128,14 @@ def from_parser_namespace( # pyright: ignore [reportIncompatibleMethodOverride]
118128
119129 return None
120130
121- def stopped_pools_func (self ):
131+ def stopped_pools_func (self ) -> Callable [[ str , Dict ], bool ] :
122132 """
123133 Function for selecting a pool from stopped pools.
124134 """
125135 selection_value = (
126- self .id_value .hex if self .id_type is IdType .UUID else self .id_value
136+ self .id_value .hex # pyright: ignore [reportAttributeAccessIssue]
137+ if self .id_type is IdType .UUID
138+ else self .id_value
127139 )
128140
129141 return (
@@ -138,12 +150,12 @@ class FilesystemId(Id):
138150 Filesystem id.
139151 """
140152
141- def __str__ (self ):
153+ def __str__ (self ) -> str :
142154 return f"filesystem with { self .id_type } { self .id_value } "
143155
144156 @staticmethod
145157 def from_parser_namespace ( # pyright: ignore [reportIncompatibleMethodOverride]
146- namespace , * , required = True
158+ namespace : Namespace , * , required = True
147159 ):
148160 assert hasattr (namespace , "name" ) and hasattr (namespace , "uuid" )
149161 if namespace .uuid is not None :
@@ -164,7 +176,7 @@ class EncryptionMethod(Enum):
164176 KEYRING = "keyring"
165177 CLEVIS = "clevis"
166178
167- def __str__ (self ):
179+ def __str__ (self ) -> str :
168180 return self .value
169181
170182
@@ -177,7 +189,7 @@ class UnlockMethod(Enum):
177189 CLEVIS = "clevis"
178190 KEYRING = "keyring"
179191
180- def __str__ (self ):
192+ def __str__ (self ) -> str :
181193 return self .value
182194
183195 def legacy_token_slot (self ): # pragma: no cover
@@ -199,7 +211,7 @@ class Clevis(Enum):
199211 TANG = "tang"
200212 TPM2 = "tpm2"
201213
202- def __str__ (self ):
214+ def __str__ (self ) -> str :
203215 return self .value
204216
205217
@@ -212,7 +224,7 @@ class IntegrityTagSpec(Enum):
212224 B32 = "32b"
213225 B512 = "512b"
214226
215- def __str__ (self ):
227+ def __str__ (self ) -> str :
216228 return self .value
217229
218230
@@ -224,5 +236,5 @@ class IntegrityOption(Enum):
224236 NO = "no"
225237 PRE_ALLOCATE = "pre-allocate"
226238
227- def __str__ (self ):
239+ def __str__ (self ) -> str :
228240 return self .value
0 commit comments