Skip to content

chore: add type annotation to cloudinit.config.cc_growpart - #7063

Open
JaneSoo wants to merge 2 commits into
canonical:mainfrom
JaneSoo:type-annotation-cc-growpart
Open

chore: add type annotation to cloudinit.config.cc_growpart#7063
JaneSoo wants to merge 2 commits into
canonical:mainfrom
JaneSoo:type-annotation-cc-growpart

Conversation

@JaneSoo

@JaneSoo JaneSoo commented Sep 1, 2026

Copy link
Copy Markdown

ref: #5445 (comment)
chore: add type annotation to cloudinit.config.cc_growpart

  • Added type annotations to all functions and methods
    • fs as Optional[str]: Can be None based on filesystem detection
    • info will be List[Tuple[str, str, str]] of device name, action/status and message. Eg: ("/dev/sda1", "CHANGED", "changed (/dev/sda, 1) from 1024 to 2048")
  • Removed cloudinit.config.cc_growpart from mypy exclusion list

Comment thread cloudinit/config/cc_growpart.py Outdated
Comment on lines +93 to +99
diskdev: Optional[str],
partnum: Optional[str],
partdev: str,
fs: Optional[str],
) -> Tuple[Optional[int], Optional[int]]:
assert diskdev is not None
assert partnum is not None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defeats the purpose of type annotations. You label it as Optional, but then throw an exception on the first line - this means that a caller that passes a NoneType will not by warned by type checking that this will crash the program.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for reviewing, I've removed the assert part and make them required str.

@JaneSoo
JaneSoo force-pushed the type-annotation-cc-growpart branch from b455f8c to 65aaa9a Compare September 1, 2026 14:11
@JaneSoo
JaneSoo requested a review from holmanb September 1, 2026 14:15

@holmanb holmanb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without dropping the module from the mypy overrides, this doesn't enable type checking on the module.

Comment thread cloudinit/config/cc_growpart.py Outdated
Comment on lines +381 to +396
if disk is not None and ptnum is None:
if disk and ptnum:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inverts the existing check.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@JaneSoo
JaneSoo force-pushed the type-annotation-cc-growpart branch from b78477e to 79f6e51 Compare September 7, 2026 11:14
@JaneSoo

JaneSoo commented Sep 7, 2026

Copy link
Copy Markdown
Author

Without dropping the module from the mypy overrides, this doesn't enable type checking on the module.

@holmanb I think the module was dropped in this commit 3082dcb#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711L39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants