Skip to content

Commit

Permalink
Add typing for __init__ functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Javagedes committed Jan 11, 2024
1 parent 0982ca8 commit 5726ada
Show file tree
Hide file tree
Showing 38 changed files with 158 additions and 127 deletions.
18 changes: 9 additions & 9 deletions edk2toollib/acpi/dmar_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DMARTable(object):
ANDDHeaderLength = 8
DeviceScopeHeaderLength = 6

def __init__(self, data: bytes) -> None:
def __init__(self, data: bytes) -> 'DMARTable':
"""Inits the object."""
self.dmar_table = self.AcpiTableHeader(data)
self.data = data[DMARTable.DMARHeaderLength:]
Expand Down Expand Up @@ -109,7 +109,7 @@ class AcpiTableHeader(object):
STRUCT_FORMAT = '=4sIBB6s8sI4sIBB'
size = struct.calcsize(STRUCT_FORMAT)

def __init__(self, header_byte_array: bytes) -> None:
def __init__(self, header_byte_array: bytes) -> 'DMARTable.AcpiTableHeader':
"""Inits the object."""
(self.Signature,
self.Length,
Expand Down Expand Up @@ -166,7 +166,7 @@ class RemappingStructHeader(object):
"""Generic remapping struct header."""
STRUCT_FORMAT = '=HH'

def __init__(self, header_byte_array: bytes) -> None:
def __init__(self, header_byte_array: bytes) -> 'DMARTable.RemappingStructHeader':
"""Inits the object."""
(self.Type,
self.Length) = struct.unpack_from(DMARTable.RemappingStructHeader.STRUCT_FORMAT, header_byte_array)
Expand All @@ -183,7 +183,7 @@ class DRHDStruct(RemappingStructHeader):
"""Object representing the DRHD struct."""
STRUCT_FORMAT = '=HHBBHQ' # spell-checker: disable-line

def __init__(self, header_byte_array: bytes, length: int) -> None:
def __init__(self, header_byte_array: bytes, length: int) -> 'DMARTable.DRHDStruct':
"""Inits the object."""
(self.Type,
self.Length,
Expand Down Expand Up @@ -244,7 +244,7 @@ class RMRRStruct(RemappingStructHeader):
"""Object representing the RMRR struct."""
STRUCT_FORMAT = '=HHHHQQ' # spell-checker: disable-line

def __init__(self, header_byte_array: bytes, length: int) -> None:
def __init__(self, header_byte_array: bytes, length: int) -> 'DMARTable.RMRRStruct':
"""Inits the object."""
(self.Type,
self.Length,
Expand Down Expand Up @@ -316,7 +316,7 @@ class ATSRStruct(RemappingStructHeader):
"""Object representing the ANDD struct."""
STRUCT_FORMAT = '=HHBBH' # spell-checker: disable-line

def __init__(self, header_byte_array: bytes, length: int) -> None:
def __init__(self, header_byte_array: bytes, length: int) -> 'DMARTable.ATSRStruct':
"""Inits the object."""
(self.Type,
self.Length,
Expand Down Expand Up @@ -374,7 +374,7 @@ class RHSAStruct(RemappingStructHeader):
"""Object representing the RHSA struct."""
STRUCT_FORMAT = '=HHIQI' # spell-checker: disable-line

def __init__(self, header_byte_array: bytes, length: int) -> None:
def __init__(self, header_byte_array: bytes, length: int) -> 'DMARTable.RHSAStruct':
"""Inits the object."""
(self.Type,
self.Length,
Expand Down Expand Up @@ -408,7 +408,7 @@ class ANDDStruct(RemappingStructHeader):
"""Object representing the ANDD struct."""
header_format = '=HH'

def __init__(self, header_byte_array: bytes, length: int) -> None:
def __init__(self, header_byte_array: bytes, length: int) -> 'DMARTable.ANDDStruct':
"""Inits the object."""
self.STRUCT_FORMAT = '=B'
(self.Type,
Expand Down Expand Up @@ -452,7 +452,7 @@ class DeviceScopeStruct(object):
"""Object representing a Device Scope."""
STRUCT_FORMAT = '=BBHBB' # spell-checker: disable-line

def __init__(self, header_byte_array: bytes) -> None:
def __init__(self, header_byte_array: bytes) -> 'DMARTable.DeviceScopeStruct':
"""Inits a DeviceScopeStruct."""
(self.Type,
self.Length,
Expand Down
30 changes: 15 additions & 15 deletions edk2toollib/acpi/ivrs_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class IVRS_TABLE(object):
"""Object representing a IVRS Table."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE':
"""Inits an empty object."""
self.acpi_header = None
self.SubStructs = list()
Expand Down Expand Up @@ -140,7 +140,7 @@ class ACPI_TABLE_HEADER(object):
struct_format = '=4sIBB6s8sI4sIIQ'
struct_format_size = struct.calcsize(struct_format)

def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.ACPI_TABLE_HEADER':
"""Inits an empty object."""
self.Signature = None
self.Length = 0
Expand Down Expand Up @@ -231,7 +231,7 @@ class REMAPPING_STRUCT_HEADER(object):
struct_format = '=B'
struct_format_size = struct.calcsize(struct_format)

def __init__(self, header_byte_array: bytes) -> None:
def __init__(self, header_byte_array: bytes) -> 'IVRS_TABLE.REMAPPING_STRUCT_HEADER':
"""Inits an empty object."""
(self.Type, ) = struct.unpack(IVRS_TABLE.REMAPPING_STRUCT_HEADER.struct_format,
header_byte_array[:IVRS_TABLE.REMAPPING_STRUCT_HEADER.struct_format_size])
Expand All @@ -250,7 +250,7 @@ class IVHD_TYPE(IntEnum):
TYPE_11H = 0x11
TYPE_40H = 0x40

def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.IVHD_STRUCT.IVHD_TYPE':
"""Inits an empty object."""
self.Type = None
self.Flags = None
Expand Down Expand Up @@ -392,7 +392,7 @@ class IVMD_TYPE(IntEnum):
TYPE_21H = 0x21 # Specified peripheral
TYPE_22H = 0x22 # Peripheral range

def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.IVMD_STRUCT':
"""Inits an empty object."""
self.Type = None
self.Flags = None
Expand Down Expand Up @@ -525,7 +525,7 @@ def Factory(data: bytes) -> Optional['IVRS_TABLE.DEVICE_TABLE_ENTRY_SPECIAL']:

class DEVICE_TABLE_ENTRY_RESERVED(object):
"""Object representing a Device Table Entry RESERVED."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.DEVICE_TABLE_ENTRY':
"""Inits an empty object."""
self.Type = 0
self.DeviceID = 0
Expand Down Expand Up @@ -577,7 +577,7 @@ def DumpInfo(self) -> None:

class DEVICE_TABLE_ENTRY_ALL(object):
"""Object representing a Device Table Entry ALL."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.DEVICE_TABLE_ENTRY_ALL':
"""Inits an empty object."""
self.Type = 0
self.DeviceID = 0
Expand Down Expand Up @@ -630,7 +630,7 @@ def DumpInfo(self) -> None:

class DEVICE_TABLE_ENTRY_SELECT(object):
"""Object representing a Device Table Entry SELECT."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.DEVICE_TABLE_ENTRY_SELECT':
"""Inits an empty object."""
self.Type = 0
self.DeviceID = 0
Expand Down Expand Up @@ -683,7 +683,7 @@ def DumpInfo(self) -> None:

class DEVICE_TABLE_ENTRY_RANGE_START(object):
"""Object representing a Device Table Entry RANGE_START."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.DEVICE_TABLE_ENTRY_RANGE_START':
"""Inits an empty object."""
self.Type = 0
self.DeviceID = 0
Expand Down Expand Up @@ -751,7 +751,7 @@ def DumpInfo(self) -> None:

class DEVICE_TABLE_ENTRY_ALIAS_SELECT(object):
"""Object representing a Device Table Entry ALIAS_SELECT."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.DEVICE_TABLE_ENTRY_ALIAS_SELECT':
"""Inits an empty object."""
self.Type = 0
self.DeviceID = 0
Expand Down Expand Up @@ -814,7 +814,7 @@ def DumpInfo(self) -> None:

class DEVICE_TABLE_ENTRY_ALIAS_RANGE_START(object):
"""Object representing a Device Table Range Start."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.DEVICE_TABLE_ENTRY_ALIAS_RANGE_START':
"""Inits an empty object."""
self.Type = 0
self.DeviceID = 0
Expand Down Expand Up @@ -892,7 +892,7 @@ def DumpInfo(self) -> None:

class DEVICE_TABLE_ENTRY_EX_SELECT(object):
"""Object representing a Device Table Entry EX_SELECT."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.DEVICE_TABLE_ENTRY_EX_SELECT':
"""Inits an empty object."""
self.Type = 0
self.DeviceID = 0
Expand Down Expand Up @@ -962,7 +962,7 @@ def DumpInfo(self) -> None:

class DEVICE_TABLE_ENTRY_EX_RANGE_START(object):
"""Object representing a Device Table Entry EX_RANGE_START."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.DEVICE_TABLE_ENTRY_EX_RANGE_START':
"""Inits an empty object."""
self.Type = 0
self.DeviceID = 0
Expand Down Expand Up @@ -1042,7 +1042,7 @@ def DumpInfo(self) -> None:

class DEVICE_TABLE_ENTRY_SPECIAL(object):
"""Object representing a Device Table Entry Special."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.DEVICE_TABLE_ENTRY_SPECIAL':
"""Inits an empty object."""
self.Type = 0
self.DeviceID = 0
Expand Down Expand Up @@ -1126,7 +1126,7 @@ def DumpInfo(self) -> None:

class DEVICE_TABLE_ENTRY_ACPI(object):
"""Object representing a Device Table Entry ACPI."""
def __init__(self, data: Optional[bytes]=None) -> None:
def __init__(self, data: Optional[bytes]=None) -> 'IVRS_TABLE.DEVICE_TABLE_ENTRY_ACPI':
"""Inits an empty object."""
self.Type = 0
self.DeviceID = 0
Expand Down
6 changes: 4 additions & 2 deletions edk2toollib/log/ansi_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ColoredFormatter(logging.Formatter):
"SECTION": AnsiColor.CYAN
}

def __init__(self, msg: str="", use_azure: bool=False) -> None:
def __init__(self, msg: str="", use_azure: bool=False) -> 'ColoredFormatter':
"""Inits the formatter."""
logging.Formatter.__init__(self, msg)
self.use_azure = use_azure
Expand Down Expand Up @@ -242,7 +242,9 @@ class ColoredStreamHandler(logging.StreamHandler):
# Control Sequence Introducer
ANSI_CSI_RE = re.compile('\001?\033\\[((?:\\d|;)*)([a-zA-Z])\002?')

def __init__(self, stream: Optional[IO]=None, strip: Optional[str]=None, convert: Optional[str]=None) -> None:
def __init__(
self, stream: Optional[IO]=None, strip: Optional[str]=None, convert: Optional[str]=None
) -> 'ColoredStreamHandler':
"""Inits a Colored Stream Handler."""
logging.StreamHandler.__init__(self, stream)
self.on_windows = GetHostInfo().os == "Windows"
Expand Down
2 changes: 1 addition & 1 deletion edk2toollib/log/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class FileHandler(logging.FileHandler):
"""Object for handling basic logging output to files."""
def __init__(self, filename: str, mode: str='w+') -> None:
def __init__(self, filename: str, mode: str='w+') -> 'FileHandler':
"""Init a file handler for the specified file."""
logging.FileHandler.__init__(self, filename, mode=mode)

Expand Down
10 changes: 5 additions & 5 deletions edk2toollib/log/junit_report_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

class JunitReportError(object):
"""Object representing a Test Error."""
def __init__(self, type: str, msg: str) -> None:
def __init__(self, type: str, msg: str) -> 'JunitReportError':
"""Init the type of error."""
self.Message = escape(msg.strip(), {'"': """})
self.Type = escape(type.strip(), {'"': """})


class JunitReportFailure(object):
"""Object representing a Test Failure."""
def __init__(self, type: str, msg: str) -> None:
def __init__(self, type: str, msg: str) -> 'JunitReportFailure':
"""Init the type of Failure."""
self.Message = escape(msg.strip(), {'"': """})
self.Type = escape(type.strip(), {'"': """})
Expand All @@ -43,7 +43,7 @@ class JunitReportTestCase(object):
ERROR = 4
SUCCESS = 5

def __init__(self, Name: str, ClassName: str) -> None:
def __init__(self, Name: str, ClassName: str) -> 'JunitReportTestCase':
"""Init a Test case with it's name and class name."""
self.Name = escape(Name.strip(), {'"': """})
self.ClassName = escape(ClassName.strip(), {'"': """})
Expand Down Expand Up @@ -121,7 +121,7 @@ class JunitReportTestSuite(object):
Create new suites by using the JunitTestReport Object
"""
def __init__(self, Name: str, Package: str, Id: id) -> None:
def __init__(self, Name: str, Package: str, Id: id) -> 'JunitReportTestSuite':
"""Initialize a new test suite."""
self.Name = escape(Name.strip(), {'"': """})
self.Package = escape(Package.strip(), {'"': """})
Expand Down Expand Up @@ -169,7 +169,7 @@ class JunitTestReport(object):
Top level object test reporting.
"""
def __init__(self) -> None:
def __init__(self) -> 'JunitTestReport':
"""Init an empty test report."""
self.TestSuites = []

Expand Down
2 changes: 1 addition & 1 deletion edk2toollib/log/string_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class StringStreamHandler(logging.StreamHandler):
"""Class for logging via StringIO."""
terminator = '\n'

def __init__(self) -> None:
def __init__(self) -> 'StringStreamHandler':
"""Init a StringStreamHandler."""
logging.Handler.__init__(self)
self.stream = io.StringIO()
Expand Down
12 changes: 6 additions & 6 deletions edk2toollib/tpm/tpm2_policy_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class PolicyHasher(object):
"""An object used to hash TPM 2.0 policies with a specified hash."""
def __init__(self, hash_type: str) -> None:
def __init__(self, hash_type: str) -> 'PolicyHasher':
"""Init the hasher with the specified hash.
Args:
Expand Down Expand Up @@ -78,7 +78,7 @@ def generate_digest(self, digest_type): # noqa

class PolicyTreeOr(object):
"""Object representing an OR junction in a policy tree."""
def __init__(self, components: Union['PolicyTreeAnd', 'PolicyTreeOr', 'PolicyTreeSolo']) -> None:
def __init__(self, components: Union['PolicyTreeAnd', 'PolicyTreeOr', 'PolicyTreeSolo']) -> 'PolicyTreeOr':
"""Inits the policy tree junction with a list of connected components.
Args:
Expand Down Expand Up @@ -127,7 +127,7 @@ def get_policy(self, hash_obj: Union['PolicyTreeAnd', 'PolicyTreeOr', 'PolicyTre

class PolicyTreeAnd(object):
"""Object representing an AND junction in a policy tree."""
def __init__(self, components: list[Union['PolicyTreeAnd', 'PolicyTreeOr', 'PolicyTreeSolo']]) -> None:
def __init__(self, components: list[Union['PolicyTreeAnd', 'PolicyTreeOr', 'PolicyTreeSolo']]) -> 'PolicyTreeAnd':
"""Inits the policy tree junction with a list of connected components."""
# ANDs must only be composed of primitives. For simplicity, I guess.
# Honestly, this has spiralled out of control, but something is better than nothing.
Expand Down Expand Up @@ -157,7 +157,7 @@ def get_policy(self, hash_obj: Union['PolicyTreeAnd', 'PolicyTreeOr', 'PolicyTre
class PolicyTreeSolo(object):
"""This object should only be used to put a single policy claim under an OR."""

def __init__(self, policy_obj: Union['PolicyTreeAnd', 'PolicyTreeOr', 'PolicyTreeSolo']) -> None:
def __init__(self, policy_obj: Union['PolicyTreeAnd', 'PolicyTreeOr', 'PolicyTreeSolo']) -> 'PolicyTreeSolo':
"""Inits the policy tree junction."""
if not hasattr(policy_obj, 'get_buffer_for_digest'):
raise ValueError("Supplied policy object is missing required functionality!")
Expand Down Expand Up @@ -193,7 +193,7 @@ def get_policy(self, hash_obj: Union['PolicyTreeAnd', 'PolicyTreeOr']) -> int:

class PolicyLocality(object):
"""Policy Primitive to describe a single assertion to create complex assertions."""
def __init__(self, localities: list[int]) -> None:
def __init__(self, localities: list[int]) -> 'PolicyLocality':
"""Init with the requested localities."""
# Update the bitfield with the requested localities.
if localities is not None:
Expand Down Expand Up @@ -245,7 +245,7 @@ def get_buffer_for_digest(self) -> str:

class PolicyCommandCode(object):
"""Policy Primitive to describe a Command code."""
def __init__(self, command_code_string: Optional[str]=None) -> None:
def __init__(self, command_code_string: Optional[str]=None) -> 'PolicyCommandCode':
"""Init with the requested command code string."""
# Check to make sure that a command_code can be found.
str_command_code_string = str(command_code_string)
Expand Down
2 changes: 1 addition & 1 deletion edk2toollib/tpm/tpm2_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

class TpmSimulator(object):
"""An object for interacting with the Tpm Simulator."""
def __init__(self, host: str='localhost', port: int=2321) -> None:
def __init__(self, host: str='localhost', port: int=2321) -> 'TpmSimulator':
"""Initialize the simulator on the requested host (ip) and port."""
super(TpmSimulator, self).__init__()

Expand Down
Loading

0 comments on commit 5726ada

Please sign in to comment.