From e6ff3651e60f9b9aeaa1201a7d15be0c82fbe02e Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Fri, 8 Jan 2021 14:13:49 +0100 Subject: [PATCH] Enable mypy on scheduler/utils.py A couple of extra hints was needed. A later patch will add type hints for some functions that is being refactored Change-Id: I9886270dea092e28a8123245a2c70c8d8c7127f3 Blueprint: support-interface-attach-with-qos-ports --- mypy-files.txt | 1 + nova/scheduler/utils.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mypy-files.txt b/mypy-files.txt index 8248c2b94069..d21c70f05f7d 100644 --- a/mypy-files.txt +++ b/mypy-files.txt @@ -1,6 +1,7 @@ nova/compute/manager.py nova/crypto.py nova/privsep/path.py +nova/scheduler/utils.py nova/virt/driver.py nova/virt/hardware.py nova/virt/libvirt/__init__.py diff --git a/nova/scheduler/utils.py b/nova/scheduler/utils.py index d0ddb751e36b..845103a008c2 100644 --- a/nova/scheduler/utils.py +++ b/nova/scheduler/utils.py @@ -17,6 +17,7 @@ import collections import re import sys +import typing as ty from urllib import parse import os_resource_classes as orc @@ -254,7 +255,7 @@ class ResourceRequest(object): if not vpmem_labels: # No vpmems required return - amount_by_rc = collections.defaultdict(int) + amount_by_rc: ty.DefaultDict[str, int] = collections.defaultdict(int) for vpmem_label in vpmem_labels: resource_class = orc.normalize_name( "PMEM_NAMESPACE_" + vpmem_label) @@ -302,7 +303,7 @@ class ResourceRequest(object): dedicated_cpus = hardware.get_dedicated_cpu_constraint(flavor) realtime_cpus = hardware.get_realtime_cpu_constraint(flavor, image) - pcpus = len(dedicated_cpus or realtime_cpus) + pcpus = len(dedicated_cpus or realtime_cpus or []) vcpus = flavor.vcpus - pcpus # apply for the VCPU resource of a 'mixed' instance @@ -428,7 +429,7 @@ class ResourceRequest(object): :return: A dict of the form {resource_class: amount} """ - ret = collections.defaultdict(lambda: 0) + ret: ty.DefaultDict[str, int] = collections.defaultdict(lambda: 0) for rg in self._rg_by_id.values(): for resource_class, amount in rg.resources.items(): ret[resource_class] += amount @@ -469,7 +470,7 @@ class ResourceRequest(object): @property def all_required_traits(self): - traits = set() + traits: ty.Set[str] = set() for rr in self._rg_by_id.values(): traits = traits.union(rr.required_traits) return traits