Skip to content

Commit d3d63ba

Browse files
committed
🐛 Fix collections.abc deprecation warning for py 3.8
1 parent 0f27d78 commit d3d63ba

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

dash/_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import uuid
2+
import collections
3+
import six
24

35

46
def interpolate_str(template, **data):
@@ -40,6 +42,12 @@ def get_asset_path(
4042
])
4143

4244

45+
def patch_collections_abc(member):
46+
if six.PY2:
47+
return getattr(collections, member)
48+
return getattr(collections.abc, member)
49+
50+
4351
class AttributeDict(dict):
4452
"""
4553
Dictionary subclass enabling attribute lookup/assignment of keys/values.

dash/dash.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
from ._utils import interpolate_str as _interpolate
3131
from ._utils import format_tag as _format_tag
3232
from ._utils import generate_hash as _generate_hash
33-
from . import _watch
3433
from ._utils import get_asset_path as _get_asset_path
34+
from ._utils import patch_collections_abc as _patch_collections_abc
35+
from . import _watch
3536
from . import _configs
3637

3738

@@ -275,7 +276,7 @@ def layout(self):
275276
return self._layout
276277

277278
def _layout_value(self):
278-
if isinstance(self._layout, collections.Callable):
279+
if isinstance(self._layout, _patch_collections_abc('Callable')):
279280
self._cached_layout = self._layout()
280281
else:
281282
self._cached_layout = self._layout
@@ -284,7 +285,7 @@ def _layout_value(self):
284285
@layout.setter
285286
def layout(self, value):
286287
if (not isinstance(value, Component) and
287-
not isinstance(value, collections.Callable)):
288+
not isinstance(value, _patch_collections_abc('Callable'))):
288289
raise exceptions.NoLayoutException(
289290
''
290291
'Layout must be a dash component '

dash/development/base_component.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import six
77

8+
from .._utils import patch_collections_abc
9+
810

911
# pylint: disable=no-init,too-few-public-methods
1012
class ComponentRegistry:
@@ -58,7 +60,7 @@ def _check_if_has_indexable_children(item):
5860

5961

6062
@six.add_metaclass(ComponentMeta)
61-
class Component(collections.MutableMapping):
63+
class Component(patch_collections_abc('MutableMapping')):
6264
class _UNDEFINED(object):
6365
def __repr__(self):
6466
return 'undefined'

0 commit comments

Comments
 (0)