From b9374a2d7f5cfaa13a153796a669c62d850ffcd9 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Thu, 11 Mar 2021 06:09:03 +0000 Subject: [PATCH] Import ABC from collections.abc for Python 3.10 compatibility. --- AUTHORS.md | 1 + src/octoprint/util/__init__.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index fae1ed362..db978f380 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -139,6 +139,7 @@ date of first contribution): * [Miroslav Šedivý](https://github.com/eumiro) * [Costas Basdekis](https://github.com/costas-basdekis) * [Joe Martella](https://github.com/martellaj) + * [Karthikeyan Singaravelan](https://github.com/tirkarthi) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index b8de4d210..33dc92862 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -26,6 +26,13 @@ import warnings from functools import wraps from typing import Union +try: + # Python 3.4+ + from collections.abc import Iterable, MutableMapping, Set +except ImportError: + # Python 2.7 + from collections import Iterable, MutableMapping, Set + import frozendict import past.builtins @@ -978,7 +985,7 @@ def dict_flatten(dictionary, prefix="", separator="."): result = {} for k, v in dictionary.items(): key = prefix + separator + k if prefix else k - if isinstance(v, collections.MutableMapping): + if isinstance(v, MutableMapping): result.update(dict_flatten(v, prefix=key, separator=separator)) else: result[key] = v @@ -1722,11 +1729,6 @@ class CountedEvent(object): class InvariantContainer(object): def __init__(self, initial_data=None, guarantee_invariant=None): - try: - from collections.abc import Iterable - except ImportError: - # Python < 3.8 - from collections import Iterable from threading import RLock if guarantee_invariant is None: @@ -1847,7 +1849,7 @@ class TypeAlreadyInQueue(Exception): self.type = t -class CaseInsensitiveSet(collections.Set): +class CaseInsensitiveSet(Set): """ Basic case insensitive set