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 deprecated warning #16

Merged
merged 2 commits into from May 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions livejson.py
Expand Up @@ -4,11 +4,14 @@
real-time. Magic.
"""

import collections
import os
import json
import warnings

from collections import (
MutableMapping,
MutableSequence,
)

warnings.filterwarnings("once", category=DeprecationWarning)

Expand Down Expand Up @@ -126,7 +129,7 @@ def __delitem__(self, key):
self.base.data = data


class _NestedDict(_NestedBase, collections.MutableMapping):
class _NestedDict(_NestedBase, MutableMapping):
"""A pseudo-dict class to replace vanilla dicts inside a livejson.File.

This "watches" for changes made to its content, then tells
Expand All @@ -151,7 +154,7 @@ def _checkType(self, key):
isinstance(key, int) else ""))


class _NestedList(_NestedBase, collections.MutableSequence):
class _NestedList(_NestedBase, MutableSequence):
"""A pseudo-list class to replace vanilla lists inside a livejson.File.

This "watches" for changes made to its content, then tells
Expand Down Expand Up @@ -182,7 +185,7 @@ class _BaseFile(_ObjectBase):
"""Class inherited by DictFile and ListFile.

This implements all the required methods common between
collections.MutableMapping and collections.MutableSequence."""
MutableMapping and MutableSequence."""
def __init__(self, path, pretty=False, sort_keys=False):
self.path = path
self.pretty = pretty
Expand Down Expand Up @@ -297,7 +300,7 @@ def __exit__(self, *args):
del self.cache


class DictFile(_BaseFile, collections.MutableMapping):
class DictFile(_BaseFile, MutableMapping):
"""A class emulating Python's dict that will update a JSON file as it is
modified.
"""
Expand All @@ -312,7 +315,7 @@ def _checkType(self, key):
isinstance(key, int) else ""))


class ListFile(_BaseFile, collections.MutableSequence):
class ListFile(_BaseFile, MutableSequence):
"""A class emulating a Python list that will update a JSON file as it is
modified. Use this class directly when creating a new file if you want the
base object to be an array.
Expand Down Expand Up @@ -358,7 +361,7 @@ def __init__(self, path, pretty=False, sort_keys=True, indent=2):
self.__class__ = ListFile

@staticmethod
def with_data(path, data):
def with_data(path, data, *args, **kwargs):
"""Initialize a new file that starts out with some data. Pass data
as a list, dict, or JSON string.
"""
Expand All @@ -373,7 +376,7 @@ def with_data(path, data):
"'livejson.File' instance if you really "
"want to do this.")
else:
f = File(path)
f = File(path, *args, **kwargs)
f.data = data
return f

Expand Down