Skip to content

Commit

Permalink
fixed #98 (enum not considered immutable)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco-Sulla committed Apr 16, 2024
1 parent e43fcca commit 255deb5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/frozendict/cool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from array import array
from frozendict import frozendict
from collections.abc import MutableMapping, MutableSequence, MutableSet

from enum import Enum

# fix for python 3.9-

Expand Down Expand Up @@ -32,11 +32,16 @@ def getItems(o):
return enumerate


def nil(x):
return x


_freeze_conversion_map = frozendict({
MutableMapping: frozendict,
bytearray: bytes,
MutableSequence: tuple,
MutableSet: frozenset,
Enum: nil,
})

_freeze_conversion_map_custom = {}
Expand Down Expand Up @@ -317,3 +322,4 @@ def deepfreeze(
del MutableMapping
del MutableSequence
del MutableSet
del Enum
9 changes: 9 additions & 0 deletions test/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from array import array
from types import MappingProxyType
from frozendict import FreezeError, FreezeWarning
from enum import Enum


class A:
Expand Down Expand Up @@ -98,6 +99,10 @@ def after_cure():
def after_cure_a(a):
return custom_a_converter(a)

@pytest.fixture
def my_enum():
Color = Enum('Color', ['RED', 'GREEN', 'BLUE'])
return Color.RED

def test_deepfreeze(before_cure, after_cure):
assert cool.deepfreeze(before_cure) == after_cure
Expand Down Expand Up @@ -193,3 +198,7 @@ def test_original_immutate():
frozen = cool.deepfreeze(unfrozen)

assert type(unfrozen["nested"]) is dict


def test_enum(my_enum):
assert cool.deepfreeze(my_enum) is my_enum

0 comments on commit 255deb5

Please sign in to comment.