Skip to content

Commit 1477076

Browse files
committed
fix: deprecation warnings involving collections.abc
1 parent 138ebae commit 1477076

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

mhdata/io/functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import typing
2-
import collections
2+
from collections import abc
33
import copy
44
import re
55

@@ -14,12 +14,12 @@ def to_basic(obj, *, stack=[]):
1414
if obj_id in stack:
1515
raise Exception("Cyclical reference detected")
1616

17-
if isinstance(obj, collections.Mapping):
17+
if isinstance(obj, abc.Mapping):
1818
# This can be converted to a dictionary
1919
return { k:to_basic(v, stack=stack+[obj_id]) for (k, v) in obj.items() }
2020
elif isinstance(obj, str):
2121
return obj
22-
elif isinstance(obj, collections.Iterable):
22+
elif isinstance(obj, abc.Iterable):
2323
return [to_basic(v, stack=stack+[obj_id]) for v in obj]
2424
else:
2525
return obj
@@ -114,7 +114,7 @@ def derive_key(dict):
114114
base_entry[key] = data_entries
115115
else:
116116
base_entry[key] = data_entries[0]
117-
elif isinstance(data_entries[0], collections.Mapping):
117+
elif isinstance(data_entries[0], abc.Mapping):
118118
util.joindicts(base_entry, data_entries[0])
119119
else:
120120
# We cannot merge a dictionary with a non-dictionary

mhdata/load/cfields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Custom fields used by the marshmallow schema
33
"""
44

5-
import collections
5+
from collections.abc import Mapping
66
from marshmallow import fields, ValidationError, Schema, pre_load, post_dump, pre_dump
77

88
from mhdata.util import group_fields, ungroup_fields
@@ -76,7 +76,7 @@ def identify_prefixes(self):
7676

7777
@pre_load
7878
def group_fields(self, data):
79-
if not isinstance(data, collections.Mapping):
79+
if not isinstance(data, Mapping):
8080
raise TypeError("Invalid data type, perhaps you forgot many=true?")
8181
groups = (list(self.__groups__ or [])
8282
+ self.identify_prefixes())

mhdata/load/validate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import itertools
2-
import collections
2+
from collections import abc
33

44
from mhdata import cfg
55
from mhdata.io import DataMap
@@ -287,7 +287,7 @@ def validate_weapons(mhdata):
287287
# Validate weapon ammo settings. Bullet types with clip size zero must have "null state" other attributes.
288288
for name, ammo_entry in mhdata.weapon_ammo_map.items():
289289
for key, data in ammo_entry.items():
290-
if not isinstance(data, collections.Mapping): continue
290+
if not isinstance(data, abc.Mapping): continue
291291
if 'clip' not in data: continue
292292

293293
if data['clip'] == 0:

mhdata/typecheck.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
This module contains such functions.
88
"""
99

10-
import collections
10+
from collections import abc
1111

1212
def is_scalar(value):
1313
"Returns true if the value is a string, number, or null"
@@ -27,19 +27,19 @@ def is_list(value):
2727
"Returns true if the object is an iterable that isn't a scalar"
2828
if is_scalar(value):
2929
return False
30-
return isinstance(value, collections.Iterable)
30+
return isinstance(value, abc.Iterable)
3131

3232

3333
def is_flat_iterable(value):
3434
"Returns true if the object is a flat iterable (not a dictionary/string)"
35-
if isinstance(value, str) or isinstance(value, collections.Mapping):
35+
if isinstance(value, str) or isinstance(value, abc.Mapping):
3636
return False
37-
return isinstance(value, collections.Iterable)
37+
return isinstance(value, abc.Iterable)
3838

3939

4040
def is_flat_dict(obj : dict) -> bool:
4141
"Returns true if the dictionary has only scalar values"
42-
if not isinstance(obj, collections.Mapping):
42+
if not isinstance(obj, abc.Mapping):
4343
raise Exception("obj is not a dictionary")
4444
return all({ is_scalar(v) for v in obj.values()})
4545

@@ -49,5 +49,5 @@ def is_flat_dict_list(obj_list) -> bool:
4949
return all(( is_flat_dict(o) for o in obj_list))
5050

5151
def is_dict(obj) -> bool:
52-
"Returns true if obj is a dictionary. Mirror for is_instance(obj, collections.Mapping)"
53-
return isinstance(obj, collections.Mapping)
52+
"Returns true if obj is a dictionary. Mirror for is_instance(obj, abc.Mapping)"
53+
return isinstance(obj, abc.Mapping)

mhdata/util/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import collections
2-
import collections.abc
1+
from collections.abc import Mapping
32
from mhdata import typecheck
43

54
from .bidict import bidict
@@ -73,7 +72,7 @@ def check_not_grouped(obj, groups):
7372
"Checks if any fields have already been grouped, and returns the ones that aren't"
7473
results = []
7574
for group in groups:
76-
if group in obj and isinstance(obj[group], collections.Mapping):
75+
if group in obj and isinstance(obj[group], Mapping):
7776
continue
7877
results.append(group)
7978
return results

0 commit comments

Comments
 (0)