Skip to content

Commit

Permalink
Version 3.2.4 (#72)
Browse files Browse the repository at this point in the history
* Fixing recursion issue #68 when using setdefault (thanks to sdementen)
* Fixing ordered_box would make 'ordered_box_values' internal helper as key in sub boxes
  • Loading branch information
cdgriffith authored Feb 1, 2019
1 parent 4291d6f commit 95017e3
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
---------

Version 3.2.4
~~~~~~~~~~~~~

* Fixing recursion issue #68 when using setdefault (thanks to sdementen)
* Fixing ordered_box would make 'ordered_box_values' internal helper as key in sub boxes

Version 3.2.3
~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2018 Chris Griffith
Copyright (c) 2017-2019 Chris Griffith

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 13 additions & 12 deletions box.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright (c) 2017-2018 - Chris Griffith - MIT License
# Copyright (c) 2017-2019 - Chris Griffith - MIT License
"""
Improved dictionary access through dot notation with additional tools.
"""
Expand Down Expand Up @@ -37,7 +37,7 @@
__all__ = ['Box', 'ConfigBox', 'BoxList', 'SBox',
'BoxError', 'BoxKeyError']
__author__ = 'Chris Griffith'
__version__ = '3.2.3'
__version__ = '3.2.4'

BOX_PARAMETERS = ('default_box', 'default_box_attr', 'conversion_box',
'frozen_box', 'camel_killer_box', 'box_it_up',
Expand Down Expand Up @@ -233,6 +233,7 @@ def _get_box_config(cls, kwargs):
'__converted': set(),
'__box_heritage': kwargs.pop('__box_heritage', None),
'__created': False,
'__ordered_box_values': [],
# Can be changed by user after box creation
'default_box': kwargs.pop('default_box', False),
'default_box_attr': kwargs.pop('default_box_attr', cls),
Expand Down Expand Up @@ -279,7 +280,7 @@ def __new__(cls, *args, **kwargs):
def __init__(self, *args, **kwargs):
self._box_config = _get_box_config(self.__class__, kwargs)
if self._box_config['ordered_box']:
self._box_config['ordered_box_values'] = []
self._box_config['__ordered_box_values'] = []
if (not self._box_config['conversion_box'] and
self._box_config['box_duplicates'] != "ignore"):
raise BoxError('box_duplicates are only for conversion_boxes')
Expand Down Expand Up @@ -318,8 +319,8 @@ def __init__(self, *args, **kwargs):

def __add_ordered(self, key):
if (self._box_config['ordered_box'] and
key not in self._box_config['ordered_box_values']):
self._box_config['ordered_box_values'].append(key)
key not in self._box_config['__ordered_box_values']):
self._box_config['__ordered_box_values'].append(key)

def box_it_up(self):
"""
Expand Down Expand Up @@ -421,7 +422,7 @@ def __getitem__(self, item, _ignore_default=False):

def keys(self):
if self._box_config['ordered_box']:
return self._box_config['ordered_box_values']
return self._box_config['__ordered_box_values']
return super(Box, self).keys()

def values(self):
Expand Down Expand Up @@ -559,8 +560,8 @@ def __delitem__(self, key):
raise BoxError('Box is frozen')
super(Box, self).__delitem__(key)
if (self._box_config['ordered_box'] and
key in self._box_config['ordered_box_values']):
self._box_config['ordered_box_values'].remove(key)
key in self._box_config['__ordered_box_values']):
self._box_config['__ordered_box_values'].remove(key)

def __delattr__(self, item):
if self._box_config['frozen_box']:
Expand All @@ -576,8 +577,8 @@ def __delattr__(self, item):
else:
object.__delattr__(self, item)
if (self._box_config['ordered_box'] and
item in self._box_config['ordered_box_values']):
self._box_config['ordered_box_values'].remove(item)
item in self._box_config['__ordered_box_values']):
self._box_config['__ordered_box_values'].remove(item)

def pop(self, key, *args):
if args:
Expand All @@ -600,7 +601,7 @@ def pop(self, key, *args):
return item

def clear(self):
self._box_config['ordered_box_values'] = []
self._box_config['__ordered_box_values'] = []
super(Box, self).clear()

def popitem(self):
Expand Down Expand Up @@ -768,7 +769,7 @@ class BoxList(list):
def __init__(self, iterable=None, box_class=Box, **box_options):
self.box_class = box_class
self.box_options = box_options
self.box_org_ref = id(iterable)
self.box_org_ref = self.box_org_ref = id(iterable) if iterable else 0
if iterable:
for x in iterable:
self.append(x)
Expand Down
5 changes: 2 additions & 3 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pytest
coverage >= 3.6
tox
pytest >= 4.1.1
coverage >= 4.5.2
pytest-cov
PyYAML; python_version <= '3.3'
ruamel.yaml; python_version >= '3.4'
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
url='https://github.com/cdgriffith/Box',
license='MIT',
author=attrs['author'],
tests_require=["pytest", "coverage >= 3.6", "tox", "pytest-cov"],
tests_require=["pytest", "coverage >= 3.6", "pytest-cov"],
install_requires=[],
author_email='chris@cdgriffith.com',
description='Advanced Python dictionaries with dot notation access',
Expand Down Expand Up @@ -56,6 +56,6 @@
'Topic :: Software Development :: Libraries :: Python Modules'
],
extras_require={
'testing': ["pytest", "coverage >= 3.6", "tox", "pytest-cov"],
'testing': ["pytest", "coverage >= 3.6", "pytest-cov"],
},
)
6 changes: 6 additions & 0 deletions test/test_functional_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,12 @@ def test_clear(self):
assert bx == {}
assert bx.keys() == []

def test_bad_recursive(self):
b = Box()
bl = b.setdefault("l", [])
bl.append(["foo"])
assert bl == [['foo']], bl


def mp_queue_test(q):
bx = q.get()
Expand Down
10 changes: 0 additions & 10 deletions tox.ini

This file was deleted.

0 comments on commit 95017e3

Please sign in to comment.