aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--immutables/__init__.py2
-rw-r--r--immutables/_map.c8
-rw-r--r--tests/test_map.py7
3 files changed, 16 insertions, 1 deletions
diff --git a/immutables/__init__.py b/immutables/__init__.py
index f6f93c7..a85dc6e 100644
--- a/immutables/__init__.py
+++ b/immutables/__init__.py
@@ -8,4 +8,4 @@ else:
__all__ = 'Map',
-__version__ = '0.4'
+__version__ = '0.5'
diff --git a/immutables/_map.c b/immutables/_map.c
index be82cd9..d0a5642 100644
--- a/immutables/_map.c
+++ b/immutables/_map.c
@@ -2679,6 +2679,14 @@ map_dump(MapObject *self);
static PyObject *
map_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
+ if (kwds != NULL && PyDict_Size(kwds) != 0) {
+ PyErr_SetString(PyExc_TypeError, "__new__ takes no keyword arguments");
+ return NULL;
+ }
+ if (args != NULL && PyTuple_Size(args) != 0) {
+ PyErr_SetString(PyExc_TypeError, "__new__ takes no positional arguments");
+ return NULL;
+ }
return (PyObject*)map_new();
}
diff --git a/tests/test_map.py b/tests/test_map.py
index 660f742..fe2a131 100644
--- a/tests/test_map.py
+++ b/tests/test_map.py
@@ -93,6 +93,13 @@ class BaseMapTest:
Map = None
+ def test_init_no_args(self):
+ with self.assertRaisesRegex(TypeError, 'positional argument'):
+ self.Map(dict(a=1))
+
+ with self.assertRaisesRegex(TypeError, 'keyword argument'):
+ self.Map(a=1)
+
def test_hashkey_helper_1(self):
k1 = HashKey(10, 'aaa')
k2 = HashKey(10, 'bbb')