Skip to content

Commit e0a07ab

Browse files
authored
Fix errors when a kwarg is named "col" (#35)
1 parent 51b1871 commit e0a07ab

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

immutables/map.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,17 @@ def __iter__(self):
433433

434434
class Map:
435435

436-
def __init__(self, col=None, **kw):
436+
def __init__(self, *args, **kw):
437+
if not args:
438+
col = None
439+
elif len(args) == 1:
440+
col = args[0]
441+
else:
442+
raise TypeError(
443+
"immutables.Map expected at most 1 arguments, "
444+
"got {}".format(len(args))
445+
)
446+
437447
self.__count = 0
438448
self.__root = BitmapNode(0, 0, [], 0)
439449
self.__hash = -1
@@ -483,8 +493,18 @@ def __eq__(self, other):
483493

484494
return True
485495

486-
def update(self, col=None, **kw):
496+
def update(self, *args, **kw):
497+
if not args:
498+
col = None
499+
elif len(args) == 1:
500+
col = args[0]
501+
else:
502+
raise TypeError(
503+
"update expected at most 1 arguments, got {}".format(len(args))
504+
)
505+
487506
it = None
507+
488508
if col is not None:
489509
if hasattr(col, 'items'):
490510
it = iter(col.items())
@@ -721,7 +741,16 @@ def __contains__(self, key):
721741
else:
722742
return True
723743

724-
def update(self, col=None, **kw):
744+
def update(self, *args, **kw):
745+
if not args:
746+
col = None
747+
elif len(args) == 1:
748+
col = args[0]
749+
else:
750+
raise TypeError(
751+
"update expected at most 1 arguments, got {}".format(len(args))
752+
)
753+
725754
if self.__mutid == 0:
726755
raise ValueError('mutation {!r} has been finished'.format(self))
727756

tests/test_map.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,11 @@ def test_map_pickle(self):
14361436
def test_map_is_subscriptable(self):
14371437
self.assertIs(self.Map[int, str], self.Map)
14381438

1439+
def test_kwarg_named_col(self):
1440+
self.assertEqual(dict(self.Map(col=0)), {"col": 0})
1441+
self.assertEqual(dict(self.Map(a=0, col=1)), {"a": 0, "col": 1})
1442+
self.assertEqual(dict(self.Map({"a": 0}, col=1)), {"a": 0, "col": 1})
1443+
14391444

14401445
class PyMapTest(BaseMapTest, unittest.TestCase):
14411446

0 commit comments

Comments
 (0)