Skip to content

Commit 29411df

Browse files
committed
Ensure dotdict/apidict doesn't have a __dict__
1 parent b95fdda commit 29411df

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

dotdict.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def __copy__( self ):
379379

380380

381381
class dotdict( dotdict_base, dict ):
382+
__slots__ = ()
382383
pass
383384

384385

@@ -453,11 +454,13 @@ def get( self, key, default=None ):
453454

454455

455456
class apidict_threading( apidict_base):
457+
__slots__ = ()
456458
_sync_mod = threading
457459

458460

459461
class apidict( apidict_base ):
460462
"""Works in both threading and multiprocessing environments."""
463+
__slots__ = ()
461464
_sync_mod = multiprocessing
462465

463466

dotdict_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
from .dotdict import dotdict, apidict, make_apidict_proxy
1818

1919

20+
def test_dotdict_slots():
21+
# Ensure resultant dotdict doesn't have a __dict__
22+
23+
dd = dotdict( a=1, b=dict( c=3 ))
24+
assert not hasattr( dd, '__dict__' )
25+
26+
ad = apidict( 1.0, dd )
27+
assert not hasattr( ad, '__dict__' )
28+
2029
def test_dotdict_smoke():
2130
# Like dict, construct from mapping, iterable and/or keywords
2231
assert "a" in dotdict({"a":1})

0 commit comments

Comments
 (0)