osbuild: fix optional-types

Optional types were provided in places but were not always correct. Add
mypy checking and fix those that fail(ed).
This commit is contained in:
Simon de Vlieger 2022-07-06 10:54:37 +02:00 committed by Christian Kellner
parent 6e66c69608
commit 3fd864e5a9
29 changed files with 209 additions and 111 deletions

View file

@ -22,7 +22,7 @@ import errno
import os
import sys
from typing import Dict
from typing import Dict, Optional
from osbuild import devices
from osbuild import loop
@ -63,8 +63,6 @@ class LoopbackService(devices.DeviceService):
def __init__(self, args: argparse.Namespace):
super().__init__(args)
self.fd = None
self.lo = None
self.ctl = loop.LoopControl()
@staticmethod

View file

@ -20,7 +20,7 @@ import subprocess
import sys
import uuid
from typing import Dict
from typing import Dict, Optional
from osbuild import devices
from osbuild.util.udev import UdevInhibitor
@ -44,7 +44,7 @@ class CryptDeviceService(devices.DeviceService):
def __init__(self, args: argparse.Namespace):
super().__init__(args)
self.devname = None
self.devname: Optional[str] = None
self.lock = None
self.check = False

View file

@ -35,7 +35,7 @@ import subprocess
import sys
import time
from typing import Dict, Tuple
from typing import Dict, Tuple, Union
from osbuild import devices
@ -108,7 +108,7 @@ class LVService(devices.DeviceService):
msg = f"Failed to set LV device ({fullname}) status: {data}"
raise RuntimeError(msg)
def volume_group_for_device(self, device: str) -> str:
def volume_group_for_device(self, device: str) -> Union[int, str]:
# Find the volume group that belongs to the device specified via `parent`
vg_name = None
count = 0
@ -193,13 +193,13 @@ class LVService(devices.DeviceService):
# Now that we have the volume group, find the major and minor
# device numbers for the logical volume
major, minor = self.device_for_logical_volume(vg, lv)
major, minor = self.device_for_logical_volume(vg, lv) # type: ignore
# Create the device node for the LV in the build root's /dev
devname = os.path.join(vg, lv)
devname = os.path.join(vg, lv) # type: ignore
fullpath = os.path.join(devpath, devname)
os.makedirs(os.path.join(devpath, vg), exist_ok=True)
os.makedirs(os.path.join(devpath, vg), exist_ok=True) # type: ignore
os.mknod(fullpath, 0o666 | stat.S_IFBLK, os.makedev(major, minor))
data = {