Skip to content

Commit a23451d

Browse files
cdgriffithBit0rCNSeniorious000gtkaczGabriel Tkacz
authored
Version 7.2.0 (#271)
* Adding #266 support for accessing nested items in BoxList using numpy-style tuple indexing (thanks to Bit0r) * Adding tests and Cython releases for Python 3.12 * Fixing #251 support for circular references in lists (thanks to Muspi Merol) * Fixing #261 altering all `__repr__` methods so that subclassing will output the correct class name (thanks to Gabriel Tkacz) * Fixing #267 Fix type 'int' not iterable (thanks to YISH) --------- Co-authored-by: Bit0r <[email protected]> Co-authored-by: Muspi Merol <[email protected]> Co-authored-by: Gabriel Tkacz <[email protected]> Co-authored-by: Gabriel Tkacz <[email protected]> Co-authored-by: YISH <[email protected]>
1 parent cc26a46 commit a23451d

File tree

11 files changed

+75
-48
lines changed

11 files changed

+75
-48
lines changed

.github/workflows/pythonpublish.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717

1818
- name: Set up Python
19-
uses: actions/setup-python@v4
19+
uses: actions/setup-python@v5
2020
with:
21-
python-version: '3.11'
21+
python-version: '3.12'
2222

2323
- name: Install Dependencies
2424
run: |
@@ -39,13 +39,13 @@ jobs:
3939
strategy:
4040
matrix:
4141
os: [macos-11, windows-latest]
42-
python-version: ["3.8", "3.9", "3.10", "3.11"]
42+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
4343
runs-on: ${{ matrix.os }}
4444

4545
steps:
46-
- uses: actions/checkout@v3
46+
- uses: actions/checkout@v4
4747
- name: Set up Python ${{ matrix.python-version }}
48-
uses: actions/setup-python@v4
48+
uses: actions/setup-python@v5
4949
with:
5050
python-version: ${{ matrix.python-version }}
5151
- name: Install dependencies
@@ -63,19 +63,19 @@ jobs:
6363
deploy-cython-manylinux:
6464
runs-on: ubuntu-latest
6565
steps:
66-
- uses: actions/checkout@v3
67-
- name: Set up Python 3.11
68-
uses: actions/setup-python@v4
66+
- uses: actions/checkout@v4
67+
- name: Set up Python 3.12
68+
uses: actions/setup-python@v5
6969
with:
70-
python-version: "3.11"
70+
python-version: "3.12"
7171

7272
- name: Build wheels
7373
run: |
7474
python -m pip install --upgrade pip
7575
pip install cibuildwheel setuptools wheel
7676
python -m cibuildwheel --output-dir dist
7777
env:
78-
CIBW_BUILD: cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp311-macosx_x86_64
78+
CIBW_BUILD: cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64
7979
CIBW_BEFORE_BUILD: pip install Cython==3.0.0
8080
CIBW_BEFORE_TEST: pip install -r requirements.txt -r requirements-test.txt setuptools wheel twine
8181
CIBW_TEST_COMMAND: pytest {package}/test -vv
@@ -87,4 +87,3 @@ jobs:
8787
run: |
8888
pip install twine
8989
twine upload dist/*-manylinux*.whl
90-
twine upload dist/*-macosx*.whl

.github/workflows/tests.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ jobs:
1313
package-checks:
1414
strategy:
1515
matrix:
16-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12-dev", "pypy-3.8"]
16+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.8"]
1717
os: [ubuntu-latest, macos-11, windows-latest]
1818
runs-on: ${{ matrix.os }}
1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v4
22+
uses: actions/setup-python@v5
2323
with:
2424
python-version: ${{ matrix.python-version }}
2525
- uses: actions/cache@v3
@@ -58,19 +58,19 @@ jobs:
5858
Remove-item box -recurse -force
5959
python -m pytest -vv
6060
- name: Upload wheel artifact
61-
uses: actions/upload-artifact@v3
61+
uses: actions/upload-artifact@v4
6262
with:
63-
name: python_box
63+
name: python_box_${{matrix.os}}_${{ matrix.python-version }}
6464
path: dist/*.whl
6565

6666
package-manylinux-checks:
6767
runs-on: ubuntu-latest
6868
steps:
69-
- uses: actions/checkout@v3
70-
- name: Set up Python 3.11
71-
uses: actions/setup-python@v4
69+
- uses: actions/checkout@v4
70+
- name: Set up Python 3.12
71+
uses: actions/setup-python@v5
7272
with:
73-
python-version: "3.11"
73+
python-version: "3.12"
7474

7575
- uses: actions/cache@v3
7676
with:
@@ -83,27 +83,27 @@ jobs:
8383
pip install cibuildwheel
8484
python -m cibuildwheel --output-dir dist
8585
env:
86-
CIBW_BUILD: cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp311-macosx_x86_64
86+
CIBW_BUILD: cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64
8787
CIBW_BEFORE_BUILD: pip install Cython==3.0.0
8888
CIBW_BEFORE_TEST: pip install -r requirements.txt -r requirements-test.txt setuptools wheel twine
8989
CIBW_TEST_COMMAND: pytest {package}/test -vv
9090

9191
- name: Upload wheel artifact
92-
uses: actions/upload-artifact@v3
92+
uses: actions/upload-artifact@v4
9393
with:
94-
name: python_box
94+
name: python_box_manylinux
9595
path: dist/*-manylinux*.whl
9696

9797
test:
9898
strategy:
9999
matrix:
100-
python-version: ["3.8", "3.9", "3.10", "3.11"]
100+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
101101
os: [ubuntu-latest, macos-11, windows-latest]
102102
runs-on: ${{ matrix.os }}
103103
steps:
104-
- uses: actions/checkout@v3
104+
- uses: actions/checkout@v4
105105
- name: Set up Python ${{ matrix.python-version }}
106-
uses: actions/setup-python@v4
106+
uses: actions/setup-python@v5
107107
with:
108108
python-version: ${{ matrix.python-version }}
109109
- uses: actions/cache@v3

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v4.6.0
44
hooks:
55
# Identify invalid files
66
- id: check-ast
@@ -20,16 +20,16 @@ repos:
2020
- id: fix-encoding-pragma
2121
- id: fix-byte-order-marker
2222
# General quality checks
23-
- id: mixed-line-ending
24-
args: [--fix=lf]
23+
# - id: mixed-line-ending
24+
# args: [--fix=lf]
2525
- id: trailing-whitespace
2626
args: [--markdown-linebreak-ext=md]
2727
- id: check-executables-have-shebangs
2828
- id: end-of-file-fixer
2929
exclude: ^test/data/.+
3030

3131
- repo: https://github.com/ambv/black
32-
rev: 23.7.0
32+
rev: 24.4.2
3333
hooks:
3434
- id: black
3535
args: [--config=.black.toml]
@@ -51,7 +51,7 @@ repos:
5151
always_run: true
5252

5353
- repo: https://github.com/pre-commit/mirrors-mypy
54-
rev: 'v1.4.1'
54+
rev: 'v1.10.0'
5555
hooks:
5656
- id: mypy
5757
types: [python]

AUTHORS.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ Code contributions:
3030
- Michał Górny (mgorny)
3131
- Serge Lu (Serge45)
3232
- Eric Prestat (ericpre)
33-
33+
- Gabriel Mitelman Tkacz (gtkacz)
34+
- Muspi Merol (CNSeniorious000)
35+
- YISH (mokeyish)
36+
- Bit0r
3437

3538

3639
Suggestions and bug reporting:

CHANGES.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
=========
33

4+
Version 7.2.0
5+
-------------
6+
7+
* Adding #266 support for accessing nested items in BoxList using numpy-style tuple indexing (thanks to Bit0r)
8+
* Adding tests and Cython releases for Python 3.12
9+
* Fixing #251 support for circular references in lists (thanks to Muspi Merol)
10+
* Fixing #261 altering all `__repr__` methods so that subclassing will output the correct class name (thanks to Gabriel Tkacz)
11+
* Fixing #267 Fix type 'int' not iterable (thanks to YISH)
12+
413
Version 7.1.1
514
-------------
615

box/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
__author__ = "Chris Griffith"
5-
__version__ = "7.1.1"
5+
__version__ = "7.2.0"
66

77
from box.box import Box
88
from box.box_list import BoxList

box/box.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ def __contains__(self, item):
415415
except BoxError:
416416
return False
417417
else:
418-
return children in self[first_item]
418+
it = self[first_item]
419+
return isinstance(it, Iterable) and children in it
419420

420421
def keys(self, dotted: Union[bool] = False):
421422
if not dotted:
@@ -777,7 +778,7 @@ def popitem(self):
777778
return key, self.pop(key)
778779

779780
def __repr__(self) -> str:
780-
return f"Box({self})"
781+
return f"{self.__class__.__name__}({self})"
781782

782783
def __str__(self) -> str:
783784
return str(self.to_dict())

box/box_list.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ def __new__(cls, *args, **kwargs):
4040
# This is required for pickling to work correctly
4141
obj.box_options = {"box_class": box.Box}
4242
obj.box_options.update(kwargs)
43-
obj.box_org_ref = 0
43+
obj.box_org_ref = None
4444
return obj
4545

4646
def __init__(self, iterable: Optional[Iterable] = None, box_class: Type[box.Box] = box.Box, **box_options):
4747
self.box_options = box_options
4848
self.box_options["box_class"] = box_class
49-
self.box_org_ref = id(iterable) if iterable else 0
49+
self.box_org_ref = iterable
5050
if iterable:
5151
for x in iterable:
5252
self.append(x)
53+
self.box_org_ref = None
5354
if box_options.get("frozen_box"):
5455

5556
def frozen(*args, **kwargs):
@@ -65,6 +66,14 @@ def __getitem__(self, item):
6566
if len(list_pos.group()) == len(item):
6667
return value
6768
return value.__getitem__(item[len(list_pos.group()) :].lstrip("."))
69+
if isinstance(item, tuple):
70+
result = self
71+
for idx in item:
72+
if isinstance(result, list):
73+
result = result[idx]
74+
else:
75+
raise BoxTypeError(f"Cannot numpy-style indexing on {type(result).__name__}.")
76+
return result
6877
return super().__getitem__(item)
6978

7079
def __delitem__(self, key):
@@ -101,7 +110,11 @@ def _convert(self, p_object):
101110
elif isinstance(p_object, box.Box):
102111
p_object._box_config.update(self.box_options)
103112
if isinstance(p_object, list) and not self._is_intact_type(p_object):
104-
p_object = self.__class__(p_object, **self.box_options)
113+
p_object = (
114+
self
115+
if p_object is self or p_object is self.box_org_ref
116+
else self.__class__(p_object, **self.box_options)
117+
)
105118
elif isinstance(p_object, BoxList):
106119
p_object.box_options.update(self.box_options)
107120
return p_object
@@ -133,7 +146,7 @@ def _dotted_helper(self) -> List[str]:
133146
return keys
134147

135148
def __repr__(self):
136-
return f"BoxList({self.to_list()})"
149+
return f"{self.__class__.__name__}({self.to_list()})"
137150

138151
def __str__(self):
139152
return str(self.to_list())

box/config_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def getfloat(self, item, default=None):
124124
return self.float(item, default)
125125

126126
def __repr__(self):
127-
return "ConfigBox({0})".format(str(self.to_dict()))
127+
return f"{self.__class__.__name__}({str(self.to_dict())})"
128128

129129
def copy(self):
130130
return ConfigBox(super().copy())

box/shorthand_box.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def toml(self) -> str:
4444
return self.to_toml()
4545

4646
def __repr__(self):
47-
return f"SBox({self})"
47+
return f"{self.__class__.__name__}({self})"
4848

4949
def copy(self) -> "SBox":
5050
return SBox(super(SBox, self).copy())
@@ -66,4 +66,4 @@ def __new__(cls, *args, **kwargs):
6666
return obj
6767

6868
def __repr__(self) -> str:
69-
return f"DDBox({self})"
69+
return f"{self.__class__.__name__}({self})"

0 commit comments

Comments
 (0)