import "collections.abc" explicitly

The Collections Abstract Base Classes is moved to the
collections.abc module, which was earlier part of the
collections module[1].

The python3 reports a warning for the same-
DeprecationWarning: Using or importing the ABCs from
'collections' instead of from 'collections.abc' is
deprecated since Python 3.3, and in 3.10 it will stop working.

This patch updates to import collection.abc module explicitly.

[1] https://docs.python.org/3/library/collections.abc.html

Change-Id: I18ba70140f9b2b53f2e97e70f64973af9d8953be
This commit is contained in:
Manpreet Kaur 2021-07-02 17:12:27 +05:30
parent 88988bba17
commit 92a3e697cb
2 changed files with 8 additions and 8 deletions

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
import collections.abc
import datetime
import re
@ -23,7 +23,7 @@ from toscaparser.elements import scalarunit
from toscaparser.utils.gettextutils import _
class Schema(collections.Mapping):
class Schema(collections.abc.Mapping):
KEYS = (
TYPE, REQUIRED, DESCRIPTION,
@ -53,7 +53,7 @@ class Schema(collections.Mapping):
def __init__(self, name, schema_dict):
self.name = name
if not isinstance(schema_dict, collections.Mapping):
if not isinstance(schema_dict, collections.abc.Mapping):
msg = (_('Schema definition of "%(pname)s" must be a dict.')
% dict(pname=name))
ExceptionCollector.appendException(InvalidSchemaError(message=msg))
@ -136,7 +136,7 @@ class Constraint(object):
if cls is not Constraint:
return super(Constraint, cls).__new__(cls)
if(not isinstance(constraint, collections.Mapping) or
if(not isinstance(constraint, collections.abc.Mapping) or
len(constraint) != 1):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('Invalid constraint schema.')))
@ -386,7 +386,7 @@ class InRange(Constraint):
def __init__(self, property_name, property_type, constraint):
super(InRange, self).__init__(property_name, property_type, constraint)
if(not isinstance(self.constraint_value, collections.Sequence) or
if(not isinstance(self.constraint_value, collections.abc.Sequence) or
(len(constraint[self.IN_RANGE]) != 2)):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('The property "in_range" '
@ -441,7 +441,7 @@ class ValidValues(Constraint):
def __init__(self, property_name, property_type, constraint):
super(ValidValues, self).__init__(property_name, property_type,
constraint)
if not isinstance(self.constraint_value, collections.Sequence):
if not isinstance(self.constraint_value, collections.abc.Sequence):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('The property "valid_values" '
'expects a list.')))

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
import collections.abc
import dateutil.parser
import logging
import numbers
@ -127,7 +127,7 @@ def validate_value_in_range(value, range, prop_name):
def validate_map(value):
if not isinstance(value, collections.Mapping):
if not isinstance(value, collections.abc.Mapping):
ExceptionCollector.appendException(
ValueError(_('"%s" is not a map.') % value))
return value