Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collections.abc deprecation warning for py 3.8 #563

Merged
merged 3 commits into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## UNRELEASED
## Fixed
- Fixed collections.abc deprecation warning for python 3.8 [#563](https://github.com/plotly/dash/pull/563)

## [0.36.0] - 2019-01-25
## Removed
- Removed support for `Event` system. Use event properties instead, for example the `n_clicks` property instead of the `click` event, see [#531](https://github.com/plotly/dash/issues/531) for details. `dash_renderer` MUST be upgraded to >=0.17.0 together with this, and it is recommended to update `dash_core_components` to >=0.43.0 and `dash_html_components` to >=0.14.0. [#550](https://github.com/plotly/dash/pull/550)
Expand Down
9 changes: 9 additions & 0 deletions dash/_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import uuid
import collections
import six


def interpolate_str(template, **data):
Expand Down Expand Up @@ -40,6 +42,13 @@ def get_asset_path(
])


# pylint: disable=no-member
def patch_collections_abc(member):
if six.PY2:
return getattr(collections, member)
return getattr(collections.abc, member)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yep, that'll work. But why did you do it this way rather than just return collections or return collections.abc, so you could use it as patch_collections_abc.Callable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a member that is different by name which is a string, this consider the module like a dict. Other solution would work too but I came up with this first.



class AttributeDict(dict):
"""
Dictionary subclass enabling attribute lookup/assignment of keys/values.
Expand Down
7 changes: 4 additions & 3 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
from ._utils import interpolate_str as _interpolate
from ._utils import format_tag as _format_tag
from ._utils import generate_hash as _generate_hash
from . import _watch
from ._utils import get_asset_path as _get_asset_path
from ._utils import patch_collections_abc as _patch_collections_abc
from . import _watch
from . import _configs


Expand Down Expand Up @@ -275,7 +276,7 @@ def layout(self):
return self._layout

def _layout_value(self):
if isinstance(self._layout, collections.Callable):
if isinstance(self._layout, _patch_collections_abc('Callable')):
self._cached_layout = self._layout()
else:
self._cached_layout = self._layout
Expand All @@ -284,7 +285,7 @@ def _layout_value(self):
@layout.setter
def layout(self, value):
if (not isinstance(value, Component) and
not isinstance(value, collections.Callable)):
not isinstance(value, _patch_collections_abc('Callable'))):
raise exceptions.NoLayoutException(
''
'Layout must be a dash component '
Expand Down
4 changes: 3 additions & 1 deletion dash/development/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import six

from .._utils import patch_collections_abc


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


@six.add_metaclass(ComponentMeta)
class Component(collections.MutableMapping):
class Component(patch_collections_abc('MutableMapping')):
class _UNDEFINED(object):
def __repr__(self):
return 'undefined'
Expand Down