63 lines
2.1 KiB
Diff
63 lines
2.1 KiB
Diff
From 754afddf141ea26956c88c7e13fe5e7ca7942654 Mon Sep 17 00:00:00 2001
|
|
From: Karthikeyan Singaravelan <tir.karthi@gmail.com>
|
|
Date: Mon, 23 Nov 2020 11:23:49 +0530
|
|
Subject: [PATCH] Fix Python 3.9 compatibility for FrozenDict due to PEP 584
|
|
implementation. (#271)
|
|
|
|
---
|
|
boltons/dictutils.py | 2 +-
|
|
tests/test_dictutils.py | 12 ++++++++++++
|
|
2 files changed, 13 insertions(+), 1 deletion(-)
|
|
|
|
diff --git boltons/dictutils.py boltons/dictutils.py
|
|
index ce5884c..8d1a4e7 100644
|
|
--- a/boltons/dictutils.py
|
|
+++ b/boltons/dictutils.py
|
|
@@ -1076,7 +1076,7 @@ def _raise_frozen_typeerror(self, *a, **kw):
|
|
"raises a TypeError, because FrozenDicts are immutable"
|
|
raise TypeError('%s object is immutable' % self.__class__.__name__)
|
|
|
|
- __setitem__ = __delitem__ = update = _raise_frozen_typeerror
|
|
+ __ior__ = __setitem__ = __delitem__ = update = _raise_frozen_typeerror
|
|
setdefault = pop = popitem = clear = _raise_frozen_typeerror
|
|
|
|
del _raise_frozen_typeerror
|
|
diff --git tests/test_dictutils.py tests/test_dictutils.py
|
|
index b6873a8..6eac812 100644
|
|
--- a/tests/test_dictutils.py
|
|
+++ b/tests/test_dictutils.py
|
|
@@ -1,5 +1,6 @@
|
|
# -*- coding: utf-8 -*-
|
|
|
|
+import sys
|
|
import pytest
|
|
|
|
from boltons.dictutils import OMD, OneToOne, ManyToMany, FrozenDict, subdict, FrozenHashError
|
|
@@ -432,6 +433,15 @@ def test_frozendict():
|
|
return
|
|
|
|
|
|
+@pytest.mark.skipif(sys.version_info < (3, 9), reason="requires python3.9 or higher")
|
|
+def test_frozendict_ior():
|
|
+ data = {'a': 'A', 'b': 'B'}
|
|
+ fd = FrozenDict(data)
|
|
+
|
|
+ with pytest.raises(TypeError, match=".*FrozenDicts are immutable.*"):
|
|
+ fd |= fd
|
|
+
|
|
+
|
|
def test_frozendict_api():
|
|
# all the read-only methods that are fine
|
|
through_methods = ['__class__',
|
|
@@ -452,8 +462,10 @@ def test_frozendict_api():
|
|
'__lt__',
|
|
'__ne__',
|
|
'__new__',
|
|
+ '__or__',
|
|
'__reduce__',
|
|
'__reversed__',
|
|
+ '__ror__',
|
|
'__setattr__',
|
|
'__sizeof__',
|
|
'__str__',
|