Skip to content

Commit fc44f19

Browse files
authored
Fix Python 3.10 Collections package import error (#271)
* Fix Python 3.10 Collections package import error * Fix Iterable,Mapping import * Fix python 3.10 import error * Fix python3.10 import
1 parent ae3e321 commit fc44f19

7 files changed

Lines changed: 20 additions & 8 deletions

File tree

maas/client/bones/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
__all__ = ["CallError", "SessionAPI"]
88

99
import typing
10-
from collections import Iterable, namedtuple
10+
11+
from collections import namedtuple
12+
from collections.abc import Iterable
1113
import json
1214
from urllib.parse import urlparse
1315

maas/client/utils/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"vars_class",
2727
]
2828

29-
from collections import Iterable, namedtuple
29+
30+
from collections import namedtuple
31+
from collections.abc import Iterable
3032
from functools import lru_cache, partial
3133
from inspect import cleandoc, getdoc
3234
from itertools import chain, cycle, repeat
@@ -175,7 +177,7 @@ def sign(uri, headers, credentials):
175177
docstring = namedtuple("docstring", ("title", "body"))
176178

177179

178-
@lru_cache(2 ** 10)
180+
@lru_cache(2**10)
179181
def parse_docstring(thing):
180182
"""Parse a Python docstring, or the docstring found on `thing`.
181183

maas/client/utils/multipart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
__all__ = ["encode_multipart_data"]
1818

19-
from collections import Iterable, Mapping
19+
from collections.abc import Iterable, Mapping
2020
from email.generator import BytesGenerator
2121
from email.mime.application import MIMEApplication
2222
from email.mime.multipart import MIMEMultipart

maas/client/viscera/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"OriginBase",
2020
]
2121

22-
from collections import defaultdict, Iterable, Mapping, Sequence
22+
from collections.abc import Iterable, Mapping, Sequence
23+
from collections import defaultdict
2324
from copy import copy
2425
from datetime import datetime
2526
from functools import wraps

maas/client/viscera/boot_source_selections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
__all__ = ["BootSourceSelection", "BootSourceSelections"]
44

5-
from collections import Sequence
65

6+
from collections.abc import Sequence
77
from . import check, Object, ObjectField, ObjectFieldRelated, ObjectSet, ObjectType
88
from .boot_sources import BootSource
99

maas/client/viscera/nodes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
__all__ = ["Node", "Nodes"]
44

5-
from collections import Sequence
5+
try:
6+
# Python <= 3.9
7+
from collections import Sequence
8+
except:
9+
# Python > 3.9
10+
from collections.abc import Sequence
11+
612
import typing
713

814
from . import (

maas/client/viscera/testing/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
__all__ = ["bind"]
44

5-
from collections import Mapping
5+
6+
from collections.abc import Mapping
67
from itertools import chain
78
from unittest.mock import Mock
89

0 commit comments

Comments
 (0)