From 5881e52edca8dc32e0b68749f94bf02a2e438e3a Mon Sep 17 00:00:00 2001 From: Joey <513358386@qq.com> Date: Thu, 16 Dec 2021 15:56:55 +0800 Subject: [PATCH] Support python3.10, import Mapping from collections.abc --- .travis.yml | 2 ++ nameko_tracer/utils.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 317cad4..d0c2f6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,8 @@ stages: jobs: include: + - python: 3.10.0 + env: DEPS="nameko==3.0.0-rc11" - python: 3.6 env: DEPS="--pre nameko" - python: 3.6 diff --git a/nameko_tracer/utils.py b/nameko_tracer/utils.py index 2d2a96b..480abcc 100644 --- a/nameko_tracer/utils.py +++ b/nameko_tracer/utils.py @@ -1,7 +1,7 @@ -import collections from importlib import import_module import json import logging +import sys import six @@ -23,6 +23,10 @@ def serialise_to_string(value): def safe_for_serialisation(value): no_op_types = six.string_types + six.integer_types + (float, type(None)) + if sys.version_info >= (3, 3): # pragma: no cover + from collections.abc import Iterable # pylint: disable=E0611,E0401 + else: # pragma: no cover + from collections import Iterable # pylint: disable=E0611,E0401 if isinstance(value, no_op_types): return value if isinstance(value, bytes): @@ -31,7 +35,7 @@ def safe_for_serialisation(value): return { safe_for_serialisation(key): safe_for_serialisation(val) for key, val in six.iteritems(value)} - if isinstance(value, collections.Iterable): + if isinstance(value, Iterable): return list(map(safe_for_serialisation, value)) try: return six.text_type(value)