Skip to content

[enhancement]: fix typing of untyped-defs #5445

Open

Description

@aciba90

Enhancement

In #5409 we enabled the check_untyped_defs mypy lint to not include more type issues and disabled modules not passing the check. Fix them all!

If you want to work any of the modules listed below, please add a comment with the name of the module you are working on so that work isn't duplicated.

Disabled modules

  • cloudinit.analyze
  • cloudinit.analyze.dump
  • cloudinit.analyze.show
  • cloudinit.cmd.devel.hotplug_hook
  • cloudinit.cmd.devel.make_mime
  • cloudinit.cmd.devel.net_convert
  • cloudinit.cmd.main
  • cloudinit.config.cc_apt_configure
  • cloudinit.config.cc_ca_certs
  • cloudinit.config.cc_growpart
  • cloudinit.config.cc_ntp
  • cloudinit.config.cc_power_state_change
  • cloudinit.config.cc_rsyslog
  • cloudinit.config.cc_ubuntu_pro
  • cloudinit.config.modules (priority)
  • cloudinit.distros
  • cloudinit.distros.alpine
  • cloudinit.distros.azurelinux
  • cloudinit.distros.bsd
  • cloudinit.distros.opensuse
  • cloudinit.distros.parsers.hostname
  • cloudinit.distros.parsers.hosts
  • cloudinit.distros.parsers.resolv_conf
  • cloudinit.distros.ubuntu
  • cloudinit.distros.ug_util (priority)
  • cloudinit.helpers (priority)
  • cloudinit.net.cmdline (priority)
  • cloudinit.net.eni
  • cloudinit.net.ephemeral
  • cloudinit.net.freebsd
  • cloudinit.net.netbsd
  • cloudinit.net.network_manager
  • cloudinit.net.network_state (priority)
  • cloudinit.net.networkd
  • cloudinit.net.sysconfig
  • cloudinit.netinfo
  • cloudinit.sources.DataSourceAzure
  • cloudinit.sources.DataSourceBigstep
  • cloudinit.sources.DataSourceCloudSigma
  • cloudinit.sources.DataSourceCloudStack
  • cloudinit.sources.DataSourceConfigDrive
  • cloudinit.sources.DataSourceDigitalOcean
  • cloudinit.sources.DataSourceEc2
  • cloudinit.sources.DataSourceExoscale
  • cloudinit.sources.DataSourceGCE
  • cloudinit.sources.DataSourceHetzner
  • cloudinit.sources.DataSourceMAAS
  • cloudinit.sources.DataSourceNoCloud
  • cloudinit.sources.DataSourceOVF
  • cloudinit.sources.DataSourceOpenNebula
  • cloudinit.sources.DataSourceOpenStack
  • cloudinit.sources.DataSourceOracle
  • cloudinit.sources.DataSourceRbxCloud
  • cloudinit.sources.DataSourceScaleway
  • cloudinit.sources.DataSourceSmartOS
  • cloudinit.sources.DataSourceVMware
  • cloudinit.sources
  • cloudinit.sources.helpers.azure
  • cloudinit.sources.helpers.ec2
  • cloudinit.sources.helpers.netlink
  • cloudinit.sources.helpers.openstack
  • cloudinit.sources.helpers.vmware.imc.config_file
  • cloudinit.sources.helpers.vmware.imc.config_nic
  • cloudinit.sources.helpers.vultr
  • cloudinit.ssh_util (priority)
  • cloudinit.stages
  • cloudinit.temp_utils
  • cloudinit.templater
  • cloudinit.user_data (priority)
  • tests.integration_tests.instances
  • tests.unittests.analyze.test_show
  • tests.unittests.cmd.devel.test_hotplug_hook
  • tests.unittests.cmd.devel.test_render
  • tests.unittests.cmd.test_clean
  • tests.unittests.cmd.test_query
  • tests.unittests.cmd.test_status
  • tests.unittests.config.test_apt_configure_sources_list_v1
  • tests.unittests.config.test_apt_configure_sources_list_v3
  • tests.unittests.config.test_apt_source_v1
  • tests.unittests.config.test_apt_source_v3
  • tests.unittests.config.test_cc_ansible
  • tests.unittests.config.test_cc_apk_configure
  • tests.unittests.config.test_cc_apt_pipelining
  • tests.unittests.config.test_cc_bootcmd
  • tests.unittests.config.test_cc_ca_certs
  • tests.unittests.config.test_cc_chef
  • tests.unittests.config.test_cc_disable_ec2_metadata
  • tests.unittests.config.test_cc_final_message
  • tests.unittests.config.test_cc_growpart
  • tests.unittests.config.test_cc_grub_dpkg
  • tests.unittests.config.test_cc_install_hotplug
  • tests.unittests.config.test_cc_keys_to_console
  • tests.unittests.config.test_cc_landscape
  • tests.unittests.config.test_cc_locale
  • tests.unittests.config.test_cc_mcollective
  • tests.unittests.config.test_cc_mounts
  • tests.unittests.config.test_cc_phone_home
  • tests.unittests.config.test_cc_power_state_change
  • tests.unittests.config.test_cc_puppet
  • tests.unittests.config.test_cc_resizefs
  • tests.unittests.config.test_cc_resolv_conf
  • tests.unittests.config.test_cc_rh_subscription
  • tests.unittests.config.test_cc_rsyslog
  • tests.unittests.config.test_cc_runcmd
  • tests.unittests.config.test_cc_snap
  • tests.unittests.config.test_cc_ssh
  • tests.unittests.config.test_cc_timezone
  • tests.unittests.config.test_cc_ubuntu_autoinstall
  • tests.unittests.config.test_cc_ubuntu_drivers
  • tests.unittests.config.test_cc_ubuntu_pro
  • tests.unittests.config.test_cc_update_etc_hosts
  • tests.unittests.config.test_cc_users_groups
  • tests.unittests.config.test_cc_wireguard
  • tests.unittests.config.test_cc_yum_add_repo
  • tests.unittests.config.test_cc_zypper_add_repo
  • tests.unittests.config.test_modules
  • tests.unittests.config.test_schema
  • tests.unittests.conftest (priority)
  • tests.unittests.distros.test_alpine
  • tests.unittests.distros.test_hosts
  • tests.unittests.distros.test_ifconfig
  • tests.unittests.distros.test_netbsd
  • tests.unittests.distros.test_netconfig
  • tests.unittests.distros.test_opensuse
  • tests.unittests.distros.test_user_data_normalize
  • tests.unittests.helpers (priority)
  • tests.unittests.net.test_dhcp
  • tests.unittests.net.test_init
  • tests.unittests.net.test_network_state
  • tests.unittests.net.test_networkd
  • tests.unittests.runs.test_merge_run
  • tests.unittests.runs.test_simple_run
  • tests.unittests.sources.azure.test_errors
  • tests.unittests.sources.azure.test_imds
  • tests.unittests.sources.helpers.test_openstack
  • tests.unittests.sources.test_aliyun
  • tests.unittests.sources.test_altcloud
  • tests.unittests.sources.test_azure
  • tests.unittests.sources.test_azure_helper
  • tests.unittests.sources.test_cloudsigma
  • tests.unittests.sources.test_common
  • tests.unittests.sources.test_configdrive
  • tests.unittests.sources.test_digitalocean
  • tests.unittests.sources.test_ec2
  • tests.unittests.sources.test_exoscale
  • tests.unittests.sources.test_gce
  • tests.unittests.sources.test_init
  • tests.unittests.sources.test_lxd
  • tests.unittests.sources.test_maas
  • tests.unittests.sources.test_nocloud
  • tests.unittests.sources.test_opennebula
  • tests.unittests.sources.test_openstack
  • tests.unittests.sources.test_oracle
  • tests.unittests.sources.test_ovf
  • tests.unittests.sources.test_rbx
  • tests.unittests.sources.test_scaleway
  • tests.unittests.sources.test_smartos
  • tests.unittests.sources.test_upcloud
  • tests.unittests.sources.test_vultr
  • tests.unittests.sources.test_wsl
  • tests.unittests.sources.vmware.test_vmware_config_file
  • tests.unittests.test__init__
  • tests.unittests.test_apport
  • tests.unittests.test_builtin_handlers
  • tests.unittests.test_cli
  • tests.unittests.test_conftest
  • tests.unittests.test_data
  • tests.unittests.test_ds_identify
  • tests.unittests.test_helpers
  • tests.unittests.test_log
  • tests.unittests.test_merging
  • tests.unittests.test_net
  • tests.unittests.test_net_activators
  • tests.unittests.test_ssh_util
  • tests.unittests.test_stages
  • tests.unittests.test_subp
  • tests.unittests.test_templating
  • tests.unittests.test_upgrade
  • tests.unittests.test_url_helper
  • tests.unittests.test_util
  • tests.unittests.util (priority)
  • netplan_schema_check
  • mock-meta

edit by @holmanb

It's nice to see all of the community contributions working on this issue :-)

Obviously this work has created quite a bit of load on maintainers. We are working to provide feedback, but we also strongly appreciate when community members review each others' PRs before we get to it - this helps to improve consensus and agreement on the best way to tackle these issues.

A few things to keep in mind as you are writing proposals and reviewing others':

Annotating all available functions is preferred. Variable types can be inferred (no annotation needed), except when they can't, and helps us all produce higher quality code.

cast(): best avoided, but at times necessary - please include a comment to explain why a cast is required
assert: please don't, this changes runtime behavior in a not-so-productive way: if your assertion just causes code to throw an assertion error before it would have produced some other exception, then we aren't catching and fixing bugs
Any / Union - these (and others like them) provide limited utility - more concrete types help humans and analyzers understand what is happening (but these can't always be avoided)

Thanks for all of the contributions, and happy hacking!

Activity

  1. aciba90 commented on Jun 25, 2024

    @aciba90
    ContributorAuthor

    It is encouraged to split this work on several PRs to ease implementation and review time.

  2. removed
    newAn issue that still needs triage
    on Jul 2, 2024
  3. bhngupta commented on Jul 23, 2024

    @bhngupta

    Hey @aciba90, this seems like an interesting issue, I am a first time contributor to this repo, can I work on this?

  4. aciba90 commented on Jul 23, 2024

    @aciba90
    ContributorAuthor

    @bhngupta, for sure, contributions are always welcomed. Please, refer to our Contributing Overview for more help.

  5. reopened this on Aug 6, 2024
  6. added a commit that references this issue on Aug 6, 2024
    d396de1
  7. 98 remaining items

  8. anujsingh-cse commented on Oct 16, 2026

    @anujsingh-cse
    Contributor

    I would like to take \cloudinit.net.networkd\ and \cloudinit.sources.helpers.openstack\ as the next focused typing slices, one PR each. I verified there are no existing claims or open PRs for these modules. Following the GH-5445 guidance, I will add full annotation coverage of each module (all function/method signatures and return values, concrete types over Any), enable \check_untyped_defs, and run the focused mypy, unit-test, and format checks.

  9. MLHipster-beep commented on Oct 17, 2026

    @MLHipster-beep

    I'd like to take tests.unittests.config.test_cc_apt_pipelining as a focused typing slice.
    I verified there is no existing claim or open PR for this module. I'll annotate the three
    test methods, replace the None arguments to handle() with a MagicMock and an empty list,
    remove the module's check_untyped_defs override, and run the focused mypy and unit-test
    checks plus tox -e check_format.

  10. Tusharkanda commented on Oct 26, 2026

    @Tusharkanda

    I'd like to work on tests.unittests.config.test_cc_chef. I verified there is no active claim or open PR for this module. I will add type annotations following the project guidelines (concrete types, no assert guards), remove its check_untyped_defs override, and run the focused unit tests and format checks.

  11. Mohith1612 commented on Oct 28, 2026

    @Mohith1612
    Contributor

    I'll take cloudinit.net.network_state next. PR to follow shortly.

  12. Siyou-Wu commented on Oct 31, 2026

    @Siyou-Wu

    I’ve completed the cloudinit.helpers slice of GH-5445 and pushed the changes to my fork.

    The change removes cloudinit.helpers from the check_untyped_defs exclusions, fixes the typing issues, and adds DefaultingConfigParser tests. tox -e check_format passes with Python 3.12.11.

    PR link: #7192

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issuehacktoberfestIssues to be completed during Hacktoberfest. Curated list of good first issue tags.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions