From 26a68b50840e39fa3dd909506cf4a90d8cc6da66 Mon Sep 17 00:00:00 2001 From: Svein Seldal Date: Wed, 15 May 2024 22:41:10 +0200 Subject: [PATCH] Clean up imports of old modules (#433) Remove compatibility leftovers from earlier versions of Python. Minimum version as of now is Python 3.6. * import Queue dates to Python 2 * import collections.*Mapping was changed to collections.abc.*Mapping in Python 3.3 * import ConfigParser dates to Python 2 * import xml.etree.cElementTree is deprecated since Python 3.3. It will pick the fastest option when using xml.etree.ElementTree. Fix some package relative imports to be consistent with surrounding code. --- canopen/lss.py | 5 +---- canopen/network.py | 5 +---- canopen/objectdictionary/__init__.py | 5 +---- canopen/objectdictionary/eds.py | 6 +----- canopen/objectdictionary/epf.py | 5 +---- canopen/pdo/__init__.py | 2 +- canopen/pdo/base.py | 5 +---- canopen/sdo/__init__.py | 2 +- canopen/sdo/base.py | 5 +---- canopen/sdo/client.py | 5 +---- canopen/variable.py | 5 +---- 11 files changed, 11 insertions(+), 39 deletions(-) diff --git a/canopen/lss.py b/canopen/lss.py index 9dee3147..d197a5a7 100644 --- a/canopen/lss.py +++ b/canopen/lss.py @@ -1,10 +1,7 @@ import logging import time import struct -try: - import queue -except ImportError: - import Queue as queue +import queue logger = logging.getLogger(__name__) diff --git a/canopen/network.py b/canopen/network.py index a1993b17..4a5a23e0 100644 --- a/canopen/network.py +++ b/canopen/network.py @@ -1,7 +1,4 @@ -try: - from collections.abc import MutableMapping -except ImportError: - from collections import MutableMapping +from collections.abc import MutableMapping import logging import threading from typing import Callable, Dict, Iterable, List, Optional, Union diff --git a/canopen/objectdictionary/__init__.py b/canopen/objectdictionary/__init__.py index 6cc762b6..a7c79c53 100644 --- a/canopen/objectdictionary/__init__.py +++ b/canopen/objectdictionary/__init__.py @@ -3,10 +3,7 @@ """ import struct from typing import Dict, Iterable, List, Optional, TextIO, Union -try: - from collections.abc import MutableMapping, Mapping -except ImportError: - from collections import MutableMapping, Mapping +from collections.abc import MutableMapping, Mapping import logging from canopen.objectdictionary.datatypes import * diff --git a/canopen/objectdictionary/eds.py b/canopen/objectdictionary/eds.py index f4d9f238..a952c8a5 100644 --- a/canopen/objectdictionary/eds.py +++ b/canopen/objectdictionary/eds.py @@ -1,11 +1,7 @@ import copy import logging import re - -try: - from configparser import RawConfigParser, NoOptionError, NoSectionError -except ImportError: - from ConfigParser import RawConfigParser, NoOptionError, NoSectionError +from configparser import RawConfigParser, NoOptionError, NoSectionError from canopen import objectdictionary from canopen.objectdictionary import ObjectDictionary, datatypes diff --git a/canopen/objectdictionary/epf.py b/canopen/objectdictionary/epf.py index f884b659..46ffe59e 100644 --- a/canopen/objectdictionary/epf.py +++ b/canopen/objectdictionary/epf.py @@ -1,7 +1,4 @@ -try: - import xml.etree.cElementTree as etree -except ImportError: - import xml.etree.ElementTree as etree +import xml.etree.ElementTree as etree import logging from canopen import objectdictionary diff --git a/canopen/pdo/__init__.py b/canopen/pdo/__init__.py index 46396e30..98edab6f 100644 --- a/canopen/pdo/__init__.py +++ b/canopen/pdo/__init__.py @@ -4,7 +4,7 @@ from canopen.pdo.base import PdoBase, Maps # Compatibility -from .base import Variable +from canopen.pdo.base import Variable logger = logging.getLogger(__name__) diff --git a/canopen/pdo/base.py b/canopen/pdo/base.py index 52a0aa04..25c10ae2 100644 --- a/canopen/pdo/base.py +++ b/canopen/pdo/base.py @@ -1,10 +1,7 @@ import threading import math from typing import Callable, Dict, Iterable, List, Optional, Union -try: - from collections.abc import Mapping -except ImportError: - from collections import Mapping +from collections.abc import Mapping import logging import binascii diff --git a/canopen/sdo/__init__.py b/canopen/sdo/__init__.py index 775a8c4e..39b8478c 100644 --- a/canopen/sdo/__init__.py +++ b/canopen/sdo/__init__.py @@ -4,4 +4,4 @@ from canopen.sdo.exceptions import SdoAbortedError, SdoCommunicationError # Compatibility -from .base import Variable, Record, Array +from canopen.sdo.base import Variable, Record, Array diff --git a/canopen/sdo/base.py b/canopen/sdo/base.py index dcd35eb3..1a2ff566 100644 --- a/canopen/sdo/base.py +++ b/canopen/sdo/base.py @@ -1,9 +1,6 @@ import binascii from typing import Iterable, Optional, Union -try: - from collections.abc import Mapping -except ImportError: - from collections import Mapping +from collections.abc import Mapping from canopen import objectdictionary from canopen.objectdictionary import ObjectDictionary diff --git a/canopen/sdo/client.py b/canopen/sdo/client.py index d64a1c14..888d3af7 100644 --- a/canopen/sdo/client.py +++ b/canopen/sdo/client.py @@ -2,10 +2,7 @@ import logging import io import time -try: - import queue -except ImportError: - import Queue as queue +import queue from canopen.network import CanError from canopen import objectdictionary diff --git a/canopen/variable.py b/canopen/variable.py index e8687660..5ca09a24 100644 --- a/canopen/variable.py +++ b/canopen/variable.py @@ -1,9 +1,6 @@ import logging from typing import Union -try: - from collections.abc import Mapping -except ImportError: - from collections import Mapping +from collections.abc import Mapping from canopen import objectdictionary