diff options
author | Yury Selivanov <yury@magic.io> | 2018-05-01 11:15:20 -0400 |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2018-05-01 11:15:20 -0400 |
commit | 4d966a1cf9acb21c9f71f2a630da11e4ac848502 (patch) | |
tree | 19f318c74eab3d2a357c2a789542b6d1fdeb6898 | |
parent | 771954f43c70d3ba6546fafcaec40ba59a7c1d44 (diff) | |
download | immutables-4d966a1cf9acb21c9f71f2a630da11e4ac848502.tar.gz immutables-4d966a1cf9acb21c9f71f2a630da11e4ac848502.zip |
Reject keyword and positional arguments in __new__. Fixes #2.
-rw-r--r-- | immutables/__init__.py | 2 | ||||
-rw-r--r-- | immutables/_map.c | 8 | ||||
-rw-r--r-- | tests/test_map.py | 7 |
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') |