Skip to content

Commit 24f647e

Browse files
Merge pull request #1235 from vojtechtrefny/3.10-devel_pylint-fixes
Fix pylint 'possibly-used-before-assignment' warnings
2 parents bde1c87 + 402a92f commit 24f647e

File tree

7 files changed

+14
-4
lines changed

7 files changed

+14
-4
lines changed

blivet/devicelibs/stratis.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def set_key(key_desc, passphrase, key_file):
155155
fd = read
156156
elif key_file:
157157
fd = os.open(key_file, os.O_RDONLY)
158+
else:
159+
raise RuntimeError("Passphrase or key file must be provided")
158160

159161
fd_list = Gio.UnixFDList()
160162
fd_list.append(fd)

blivet/devicetree.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ def resolve_device(self, devspec, blkid_tab=None, crypt_tab=None, options=None,
752752
break
753753
elif options:
754754
attr = None
755+
val = None
755756
if "subvol=" in options:
756757
attr = "name"
757758
val = util.get_option_value("subvol", options)

blivet/formats/luks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ def add_passphrase(self, passphrase):
400400
context = blockdev.CryptoKeyslotContext(passphrase=self.__passphrase)
401401
elif self._key_file:
402402
context = blockdev.CryptoKeyslotContext(keyfile=self._key_file)
403+
else:
404+
raise LUKSError("luks device not configured")
403405

404406
ncontext = blockdev.CryptoKeyslotContext(passphrase=passphrase)
405407

blivet/tasks/availability.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ def availability_errors(self, resource):
283283
avail, _mode, utility = self.check_fn(self.fstype)
284284
elif self.operation == FSOperation.MKFS:
285285
avail, _options, utility = self.check_fn(self.fstype)
286+
else:
287+
raise RuntimeError("Unknown operation")
286288
except blockdev.FSError as e:
287289
return [str(e)]
288290
if not avail:

blivet/udev.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def get_device(sysfs_path=None, device_node=None):
8686
device = pyudev.Devices.from_sys_path(global_udev, sysfs_path)
8787
elif device_node is not None:
8888
device = pyudev.Devices.from_device_file(global_udev, device_node)
89+
else:
90+
raise RuntimeError("At least one of 'sysfs_path' and 'device_node' must be specified")
8991
except pyudev.DeviceNotFoundError as e:
9092
log.error(e)
9193
result = None

tests/pylint/runpylint.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ def __init__(self):
2323
FalsePositive(r"Method 'do_task' is abstract in class 'UnimplementedTask' but is not overridden"),
2424
FalsePositive(r"No value for argument 'member_count' in unbound method call$"),
2525
FalsePositive(r"No value for argument 'smallest_member_size' in unbound method call$"),
26-
FalsePositive(r"Bad option value '(subprocess-popen-preexec-fn|try-except-raise|environment-modify|arguments-renamed|redundant-u-string-prefix)'"),
26+
FalsePositive(r"Bad option value '(subprocess-popen-preexec-fn|try-except-raise|environment-modify|arguments-renamed|redundant-u-string-prefix|possibly-used-before-assignment)'"),
2727
FalsePositive(r"Instance of '(Action.*Device|Action.*Format|Action.*Member|Device|DeviceAction|DeviceFormat|Event|ObjectID|PartitionDevice|StorageDevice|BTRFS.*Device|LoopDevice)' has no 'id' member$"),
2828
FalsePositive(r"Instance of 'GError' has no 'message' member"), # overriding currently broken local pylint disable
29-
FalsePositive(r"No name '.*' in module 'libmount'")
29+
FalsePositive(r"No name '.*' in module 'libmount'"),
30+
FalsePositive(r"Unknown option value for 'disable', expected a valid pylint message and got 'possibly-used-before-assignment'")
3031
]
3132

3233
def _files(self):

tests/run_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def _should_skip(distro=None, version=None, arch=None, reason=None): # pylint:
134134

135135
# DISTRO, VERSION and ARCH variables are set in main, we don't need to
136136
# call hostnamectl etc. for every test run
137-
if ((distro is None or DISTRO in distro) and (version is None or VERSION in version) and # pylint: disable=used-before-assignment
138-
(arch is None or ARCH in arch)): # pylint: disable=used-before-assignment
137+
if ((distro is None or DISTRO in distro) and (version is None or VERSION in version) and # pylint: disable=used-before-assignment,possibly-used-before-assignment
138+
(arch is None or ARCH in arch)): # pylint: disable=used-before-assignment,possibly-used-before-assignment
139139
return True
140140

141141
return False

0 commit comments

Comments
 (0)