Skip to content
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

fix untyped-defs on /cloudinit/config & /tests/config/ #5985

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MostafaTarek124eru
Copy link

@MostafaTarek124eru MostafaTarek124eru commented Jan 21, 2025

Related to 5445

Part of the Onboarding.

✓ cloudinit.config.cc_power_state_change
✓ cloudinit.config.cc_rsyslog
✓ cloudinit.config.cc_ubuntu_pro
✓ tests/unittests/config/test_cc_rsyslog
✓ tests/unittests/config/test_cc_ubuntu_pro
✓ests/unittests/config/test_cc_power_state_change

Proposed Commit Message

fix untyped-defs on /cloudinit/config & /tests/config/

Additional Context

Test Steps

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

Copy link
Author

@MostafaTarek124eru MostafaTarek124eru left a comment

Choose a reason for hiding this comment

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

contributing to GH5445 as part of my on-boarding.

I've signed the CLA and ran the test.
Thanks to take a loot and check if anything else is needed

Copy link
Member

@holmanb holmanb left a comment

Choose a reason for hiding this comment

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

@MostafaTarek124eru welcome to cloud-init! I left two comments inline. Also, please sign the cla.

@@ -225,7 +226,10 @@ def configure_pro(token, enable=None):
# related. We can distinguish them by checking if `service` is non-null
# or null respectively.

enable_errors: List[dict] = []

def handle_enable_errors(enable_resp: Dict[str, Any]):
Copy link
Member

Choose a reason for hiding this comment

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

Making this a separate function makes the comment above nonsensical - it was describing this code yet it is no longer co-located with the code.

@@ -246,6 +246,7 @@ def __init__(
self.proto = proto

self.addr = addr
self.port = int(port) if port else None
Copy link
Member

Choose a reason for hiding this comment

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

This logic looks functionally identical to the next four lines. Why is it necessary?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed it in the new commit

@@ -246,7 +246,7 @@ def __init__(
self.proto = proto

self.addr = addr
self.port = int(port) if port else None
self.port = port
Copy link
Member

Choose a reason for hiding this comment

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

self.port is assigned in both branches of the following if / else. This does nothing.

except json.JSONDecodeError as e:
raise RuntimeError(
f"Pro response was not json: {enable_stdout}"
) from e


def handle_enable_errors(enable_resp: Dict[str, Any]):
Copy link
Member

Choose a reason for hiding this comment

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

This silences valid mypy warnings without solving the underlying issue

consider:

>>> import json
>>> json.loads("[]")
[]

But this just told mypy that the type will be Dict[str, Any].

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.

3 participants