Skip to content
Closed
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Code contributions:
- Jesper Schlegel (jesperschlegel)
- J vanBemmel (jbemmel)
- m-janicki
- WU Leizhi (MbappeWU)


Suggestions and bug reporting:
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

Unreleased
----------

* Fixing compiled Box nested construction with a compiled ``box_dots_exclude`` pattern

Version 7.4.1
-------------

Expand Down
4 changes: 2 additions & 2 deletions box/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __new__(
box_intact_types: tuple | list = (),
box_recast: dict | None = None,
box_dots: bool = False,
box_dots_exclude: str | None = None,
box_dots_exclude: str | re.Pattern[str] | None = None,
box_class: dict | type[Box] | None = None,
box_namespace: tuple[str, ...] | Literal[False] = (),
**kwargs: Any,
Expand Down Expand Up @@ -255,7 +255,7 @@ def __init__(
box_intact_types: tuple | list = (),
box_recast: dict | None = None,
box_dots: bool = False,
box_dots_exclude: str | None = None,
box_dots_exclude: str | re.Pattern[str] | None = None,
box_class: dict | type[Box] | None = None,
box_namespace: tuple[str, ...] | Literal[False] = (),
**kwargs: Any,
Expand Down
5 changes: 3 additions & 2 deletions box/box.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from _typeshed import Incomplete
from collections.abc import Generator, Mapping
from os import PathLike
import re
from typing import Any, Literal

class Box(dict):
Expand All @@ -20,7 +21,7 @@ class Box(dict):
box_intact_types: tuple | list = ...,
box_recast: dict | None = ...,
box_dots: bool = ...,
box_dots_exclude: str | None = ...,
box_dots_exclude: str | re.Pattern[str] | None = ...,
box_class: dict | type[Box] | None = ...,
box_namespace: tuple[str, ...] | Literal[False] = ...,
**kwargs: Any,
Expand All @@ -41,7 +42,7 @@ class Box(dict):
box_intact_types: tuple | list = ...,
box_recast: dict | None = ...,
box_dots: bool = ...,
box_dots_exclude: str | None = ...,
box_dots_exclude: str | re.Pattern[str] | None = ...,
box_class: dict | type[Box] | None = ...,
box_namespace: tuple[str, ...] | Literal[False] = ...,
**kwargs: Any,
Expand Down
27 changes: 27 additions & 0 deletions test/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import pickle
import platform
import re
import shutil
from multiprocessing import Queue
from pathlib import Path
Expand Down Expand Up @@ -957,6 +958,32 @@ def test_dots_exclusion(self):
with pytest.raises(BoxKeyError):
del bx["0"]

@pytest.mark.parametrize(
"exclude",
[r"(?im)^secret\.", re.compile(r"^secret\.", re.IGNORECASE | re.MULTILINE)],
)
def test_dots_exclusion_pattern_propagates(self, exclude):
expected = re.compile(exclude)
bx = Box(
{"Secret.Key": 1, "nested": {"Secret.Key": 2}, "items": [{"Secret.Key": 3}]},
box_dots=True,
box_dots_exclude=exclude,
)

assert bx["Secret.Key"] == 1
assert bx.nested["Secret.Key"] == 2
assert bx["items"][0]["Secret.Key"] == 3
assert bx.nested._box_config["box_dots_exclude"].flags == expected.flags
assert bx["items"].box_options["box_dots_exclude"].flags == expected.flags
assert bx["items"][0]._box_config["box_dots_exclude"].flags == expected.flags
assert bx._box_config["box_dots_exclude"].flags == expected.flags

for copied in (bx.copy(), copy.copy(bx), copy.deepcopy(bx)):
assert copied["Secret.Key"] == 1
assert copied.nested["Secret.Key"] == 2
assert copied["items"][0]["Secret.Key"] == 3
assert copied._box_config["box_dots_exclude"].flags == expected.flags

def test_unicode(self):
bx = Box()
bx["\U0001f631"] = 4
Expand Down