Skip to content

Commit

Permalink
Clean up imports of old modules (christiansandberg#433)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sveinse authored May 15, 2024
1 parent b55ce5c commit 26a68b5
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 39 deletions.
5 changes: 1 addition & 4 deletions canopen/lss.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down
5 changes: 1 addition & 4 deletions canopen/network.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions canopen/objectdictionary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
6 changes: 1 addition & 5 deletions canopen/objectdictionary/eds.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions canopen/objectdictionary/epf.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion canopen/pdo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
5 changes: 1 addition & 4 deletions canopen/pdo/base.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion canopen/sdo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions canopen/sdo/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions canopen/sdo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions canopen/variable.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 26a68b5

Please sign in to comment.