Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions immutables/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,17 @@ def __iter__(self):

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
Expand Down Expand Up @@ -483,8 +493,18 @@ def __eq__(self, other):

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())
Expand Down Expand Up @@ -721,7 +741,16 @@ def __contains__(self, key):
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))

Expand Down
5 changes: 5 additions & 0 deletions tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,11 @@ def test_map_pickle(self):
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})
Copy link
Author

@hukkin hukkin May 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these three asserts used to fail when running in PyMapTest. They now pass with the changes in this MR.

This test makes very little sense now that the keyword arg called "col" has been refactored out, though. Should we keep it or not?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK to keep it I guess.



class PyMapTest(BaseMapTest, unittest.TestCase):

Expand Down