-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use TypedDict to annotate disk-related serializations #2935
Use TypedDict to annotate disk-related serializations #2935
Conversation
@@ -96,7 +103,7 @@ def parse_arg(cls, disk_config: dict[str, Any]) -> DiskLayoutConfiguration | Non | |||
return config | |||
|
|||
for entry in disk_config.get('device_modifications', []): | |||
device_path = Path(entry.get('device', None)) if entry.get('device', None) else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the conditional get
to avoid this error:
error: Argument 1 to "Path" has incompatible type "str | None"; expected "str | PathLike[str]" [arg-type]
return { | ||
'value': self.value, | ||
'unit': self.unit.name, | ||
'sector_size': self.sector_size.json() if self.sector_size else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like self.sector_size
can be None
given the __post_init__
code above. I changed the code to avoid this mypy error:
error: Incompatible types (expression has type "_SectorSizeSerialization | None", TypedDict item "sector_size" has type "_SectorSizeSerialization") [typeddict-item]
lvm_pvs = [] | ||
for mod in disk_config.device_modifications: | ||
for part in mod.partitions: | ||
if part.obj_id in arg.get('lvm_pvs', []): | ||
# FIXME: 'lvm_pvs' does not seem like it can ever exist in the 'arg' serialization | ||
if part.obj_id in arg.get('lvm_pvs', []): # type: ignore[operator] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this arg.get('lvm_pvs', [])
call can ever succeed.
It looks like the LvmVolumeGroup data needs to be checked instead.
PR Description:
This PR reduces the number of
Any
instances in the code. I think mypy is now catching a real bug inLvmConfiguration.parse_arg
too.