aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--immutables/map.py35
-rw-r--r--tests/test_map.py5
2 files changed, 37 insertions, 3 deletions
diff --git a/immutables/map.py b/immutables/map.py
index a8cffd4..ac7ebd7 100644
--- a/immutables/map.py
+++ b/immutables/map.py
@@ -433,7 +433,17 @@ class MapItems:
class Map:
- def __init__(self, col=None, **kw):
+ def __init__(self, *args, **kw):
+ if not args:
+ col = None
+ elif len(args) == 1:
+ col = args[0]
+ else:
+ raise TypeError(
+ "immutables.Map expected at most 1 arguments, "
+ "got {}".format(len(args))
+ )
+
self.__count = 0
self.__root = BitmapNode(0, 0, [], 0)
self.__hash = -1
@@ -483,8 +493,18 @@ class Map:
return True
- def update(self, col=None, **kw):
+ def update(self, *args, **kw):
+ if not args:
+ col = None
+ elif len(args) == 1:
+ col = args[0]
+ else:
+ raise TypeError(
+ "update expected at most 1 arguments, got {}".format(len(args))
+ )
+
it = None
+
if col is not None:
if hasattr(col, 'items'):
it = iter(col.items())
@@ -721,7 +741,16 @@ class MapMutation:
else:
return True
- def update(self, col=None, **kw):
+ def update(self, *args, **kw):
+ if not args:
+ col = None
+ elif len(args) == 1:
+ col = args[0]
+ else:
+ raise TypeError(
+ "update expected at most 1 arguments, got {}".format(len(args))
+ )
+
if self.__mutid == 0:
raise ValueError('mutation {!r} has been finished'.format(self))
diff --git a/tests/test_map.py b/tests/test_map.py
index 5c4e1fb..37b5b65 100644
--- a/tests/test_map.py
+++ b/tests/test_map.py
@@ -1436,6 +1436,11 @@ class BaseMapTest:
def test_map_is_subscriptable(self):
self.assertIs(self.Map[int, str], self.Map)
+ def test_kwarg_named_col(self):
+ self.assertEqual(dict(self.Map(col=0)), {"col": 0})
+ self.assertEqual(dict(self.Map(a=0, col=1)), {"a": 0, "col": 1})
+ self.assertEqual(dict(self.Map({"a": 0}, col=1)), {"a": 0, "col": 1})
+
class PyMapTest(BaseMapTest, unittest.TestCase):